Class AbstractTestServiceManager
java.lang.Object
test.de.iip_ecosphere.platform.services.spring.AbstractTest
test.de.iip_ecosphere.platform.services.spring.AbstractTestServiceManager
- Direct Known Subclasses:
EnsembleStartStopServiceManagerTest,ServerStartStopServiceManagerTest,SimpleStartStopServiceManagerTest,ZipCpServiceManagerTest,ZipNoCpServiceManagerTest
Abstract, common test for service manager/service execution tests.
- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classArtifact asserter interface.protected static classA fake service implementation for testing. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static de.iip_ecosphere.platform.support.Serverprivate de.iip_ecosphere.platform.services.spring.SpringCloudServiceSetupprivate static de.iip_ecosphere.platform.support.Serverprivate static de.iip_ecosphere.platform.support.Serverprivate static de.iip_ecosphere.platform.support.iip_aas.ActiveAasBase.NotificationModeprivate static de.iip_ecosphere.platform.support.iip_aas.AasPartRegistry.AasSetupA predicate testing whether the value of a JSON gauge is positive.private static de.iip_ecosphere.platform.support.Serverprivate List<de.iip_ecosphere.platform.support.Server> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static final voidassertFileExists(File file) Asserts thatfileexists.protected voidAsserts the existence of selected AAS metrics and/or their values.protected static voidAsserts the receiver log.private static voidassertServiceState(String[] serviceIds, de.iip_ecosphere.platform.services.ArtifactDescriptor aDesc, de.iip_ecosphere.platform.services.environment.ServiceState expectedState) Asserts the service states for the services inserviceId.private voidassertUsageCount(de.iip_ecosphere.platform.services.ArtifactDescriptor aDesc, int count) Asserts the given usage count onaDesc.protected voiddoTestStartStop(String descriptorName, AbstractTestServiceManager.ArtifactAsserter asserter, boolean fakeServer) Implements the tests for a start-stop scenario with different descriptors/related asserters.protected voiddoTestStartStop(String descriptorName, AbstractTestServiceManager.ArtifactAsserter asserter, boolean fakeServer, Function<String, String> serviceIdAdapter) Implements the tests for a start-stop scenario with different descriptors/related asserters.getAllServiceIds(de.iip_ecosphere.platform.services.ArtifactDescriptor aDesc, Function<String, String> serviceIdAdapter) Returns all service ids in the given artifact descriptor.protected de.iip_ecosphere.platform.services.spring.SpringCloudServiceSetupReturns the configuration instance.static voidinit(de.iip_ecosphere.platform.support.ServerAddress broker) Initializes the test by starting an embedded AMQP server.protected static voidinitialize(org.springframework.context.ConfigurableApplicationContext applicationContext, de.iip_ecosphere.platform.support.ServerAddress broker) Initializes the application context for testing.private static List<de.iip_ecosphere.platform.services.environment.services.TransportConverter.Watcher<String>> loggingOp(de.iip_ecosphere.platform.services.ServiceManager mgr, de.iip_ecosphere.platform.services.ServiceOperations.StreamLogMode mode, String... ids) Performs a log streaming operation on services with givenids.protected voidRelease the servers created instartFakeServiceCommandServers(ServiceManager, String[]).static voidshutdown()Shuts down client and test server.protected voidstartFakeServiceCommandServers(de.iip_ecosphere.platform.services.ServiceManager mgr, String[] ids) Starts fake service command servers to test the integration ofServiceStub.private voidstartServices(de.iip_ecosphere.platform.services.ServiceManager mgr, AbstractTestServiceManager.ArtifactAsserter asserter, String... allIds) StartsallIdsonmgreventually consideringAbstractTestServiceManager.ArtifactAsserter.getOptions().private static voidstopLogging(List<de.iip_ecosphere.platform.services.environment.services.TransportConverter.Watcher<String>> watcher) Stops running logging watchers.protected voidtestWithZipArchive(boolean useClasspath) Tests service start/stop with the ZIP artifact containing explicit dependency JARs.
-
Field Details
-
POSITIVE_GAUGE_VALUE
A predicate testing whether the value of a JSON gauge is positive. -
server
private static de.iip_ecosphere.platform.support.Server server -
oldM
private static de.iip_ecosphere.platform.support.iip_aas.ActiveAasBase.NotificationMode oldM -
oldSetup
private static de.iip_ecosphere.platform.support.iip_aas.AasPartRegistry.AasSetup oldSetup -
implServer
private static de.iip_ecosphere.platform.support.Server implServer -
aasServer
private static de.iip_ecosphere.platform.support.Server aasServer -
gatewayServer
private static de.iip_ecosphere.platform.support.Server gatewayServer -
config
@Autowired private de.iip_ecosphere.platform.services.spring.SpringCloudServiceSetup config -
netKeyToRelease
-
serversToRelease
-
-
Constructor Details
-
AbstractTestServiceManager
public AbstractTestServiceManager()
-
-
Method Details
-
getConfig
protected de.iip_ecosphere.platform.services.spring.SpringCloudServiceSetup getConfig()Returns the configuration instance.- Returns:
- the configuration instance
-
init
public static void init(de.iip_ecosphere.platform.support.ServerAddress broker) Initializes the test by starting an embedded AMQP server. Requires the Qpid configuration file in src/test. We do not rely on MQTT here, because Moquette is not stable enough and Hivemq requires JDK 11.- Parameters:
broker- the broker address
-
shutdown
public static void shutdown()Shuts down client and test server. -
assertFileExists
Asserts thatfileexists.- Parameters:
file- the file
-
assertUsageCount
private void assertUsageCount(de.iip_ecosphere.platform.services.ArtifactDescriptor aDesc, int count) Asserts the given usage count onaDesc.- Parameters:
aDesc- the artifact descriptorcount- the expected usage count
-
doTestStartStop
protected void doTestStartStop(String descriptorName, AbstractTestServiceManager.ArtifactAsserter asserter, boolean fakeServer) throws ExecutionException, IOException Implements the tests for a start-stop scenario with different descriptors/related asserters.- Parameters:
descriptorName- the descriptor nameasserter- the asserter related to descriptor-specific propertiesfakeServer- fake command servers for services - clashes with services that are based on the service environment- Throws:
ExecutionException- if executing service operations failsIOException- if accessing metrics fails
-
startServices
private void startServices(de.iip_ecosphere.platform.services.ServiceManager mgr, AbstractTestServiceManager.ArtifactAsserter asserter, String... allIds) throws ExecutionException StartsallIdsonmgreventually consideringAbstractTestServiceManager.ArtifactAsserter.getOptions().- Parameters:
mgr- the manager to start onasserter- the asserterallIds- the service ids- Throws:
ExecutionException- the execution exceptions
-
doTestStartStop
protected void doTestStartStop(String descriptorName, AbstractTestServiceManager.ArtifactAsserter asserter, boolean fakeServer, Function<String, String> serviceIdAdapter) throws ExecutionException, IOExceptionImplements the tests for a start-stop scenario with different descriptors/related asserters.- Parameters:
descriptorName- the descriptor nameasserter- the asserter related to descriptor-specific propertiesfakeServer- fake command servers for services - clashes with services that are based on the service environmentserviceIdAdapter- function to modify the service ids, e.g., to add app/app instance id- Throws:
ExecutionException- if executing service operations failsIOException- if accessing metrics fails
-
loggingOp
private static List<de.iip_ecosphere.platform.services.environment.services.TransportConverter.Watcher<String>> loggingOp(de.iip_ecosphere.platform.services.ServiceManager mgr, de.iip_ecosphere.platform.services.ServiceOperations.StreamLogMode mode, String... ids) Performs a log streaming operation on services with givenids.- Parameters:
mgr- the service managermode- the logging modeids- the service ids- Returns:
- the created/started watchers
-
stopLogging
private static void stopLogging(List<de.iip_ecosphere.platform.services.environment.services.TransportConverter.Watcher<String>> watcher) Stops running logging watchers.- Parameters:
watcher- the logging watchers
-
getAllServiceIds
private static Set<String> getAllServiceIds(de.iip_ecosphere.platform.services.ArtifactDescriptor aDesc, Function<String, String> serviceIdAdapter) Returns all service ids in the given artifact descriptor. Emulates AAS result with all server-as-service ids.- Parameters:
aDesc- the artifact descriptorserviceIdAdapter- function to modify the service ids, e.g., to add app/app instance id- Returns:
- the service ids
-
assertServiceState
private static void assertServiceState(String[] serviceIds, de.iip_ecosphere.platform.services.ArtifactDescriptor aDesc, de.iip_ecosphere.platform.services.environment.ServiceState expectedState) Asserts the service states for the services inserviceId.- Parameters:
serviceIds- the ids of the services to assertaDesc- the artifact descriptor to obtain the services fromexpectedState- the expected state
-
assertReceiverLog
protected static void assertReceiverLog()Asserts the receiver log. -
assertMetrics
protected void assertMetrics(String[] ids, Map<String, Predicate<Object>> expected) throws IOException, ExecutionExceptionAsserts the existence of selected AAS metrics and/or their values.- Parameters:
ids- service idsexpected- the expected metrics as key-predicate pairs, whereby the predicate may be null to indicated that the value shall not be tested- Throws:
IOException- if the AAS cannot be retrievedExecutionException- if a property cannot be queried
-
startFakeServiceCommandServers
protected void startFakeServiceCommandServers(de.iip_ecosphere.platform.services.ServiceManager mgr, String[] ids) Starts fake service command servers to test the integration ofServiceStub.- Parameters:
mgr- the service managerids- the ids of the services to start
-
releaseFakeServiceCommandServers
protected void releaseFakeServiceCommandServers()Release the servers created instartFakeServiceCommandServers(ServiceManager, String[]). -
testWithZipArchive
Tests service start/stop with the ZIP artifact containing explicit dependency JARs.- Parameters:
useClasspath- consider classpath file- Throws:
ExecutionException- shall not occur
-
initialize
protected static void initialize(org.springframework.context.ConfigurableApplicationContext applicationContext, de.iip_ecosphere.platform.support.ServerAddress broker) Initializes the application context for testing.- Parameters:
applicationContext- the application contextbroker- the broker address
-