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

public class AbstractTestServiceManager extends AbstractTest
Abstract, common test for service manager/service execution tests.
Author:
Holger Eichelberger, SSE
  • Field Details

    • POSITIVE_GAUGE_VALUE

      protected static final Predicate<Object> 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

      private List<String> netKeyToRelease
    • serversToRelease

      private List<de.iip_ecosphere.platform.support.Server> 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

      protected static final void assertFileExists(File file)
      Asserts that file exists.
      Parameters:
      file - the file
    • assertUsageCount

      private void assertUsageCount(de.iip_ecosphere.platform.services.ArtifactDescriptor aDesc, int count)
      Asserts the given usage count on aDesc.
      Parameters:
      aDesc - the artifact descriptor
      count - 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 name
      asserter - the asserter related to descriptor-specific properties
      fakeServer - fake command servers for services - clashes with services that are based on the service environment
      Throws:
      ExecutionException - if executing service operations fails
      IOException - if accessing metrics fails
    • startServices

      private void startServices(de.iip_ecosphere.platform.services.ServiceManager mgr, AbstractTestServiceManager.ArtifactAsserter asserter, String... allIds) throws ExecutionException
      Starts allIds on mgr eventually considering AbstractTestServiceManager.ArtifactAsserter.getOptions().
      Parameters:
      mgr - the manager to start on
      asserter - the asserter
      allIds - 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, IOException
      Implements the tests for a start-stop scenario with different descriptors/related asserters.
      Parameters:
      descriptorName - the descriptor name
      asserter - the asserter related to descriptor-specific properties
      fakeServer - fake command servers for services - clashes with services that are based on the service environment
      serviceIdAdapter - function to modify the service ids, e.g., to add app/app instance id
      Throws:
      ExecutionException - if executing service operations fails
      IOException - 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 given ids.
      Parameters:
      mgr - the service manager
      mode - the logging mode
      ids - 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 descriptor
      serviceIdAdapter - 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 in serviceId.
      Parameters:
      serviceIds - the ids of the services to assert
      aDesc - the artifact descriptor to obtain the services from
      expectedState - 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, ExecutionException
      Asserts the existence of selected AAS metrics and/or their values.
      Parameters:
      ids - service ids
      expected - 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 retrieved
      ExecutionException - 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 of ServiceStub.
      Parameters:
      mgr - the service manager
      ids - the ids of the services to start
    • releaseFakeServiceCommandServers

      protected void releaseFakeServiceCommandServers()
    • testWithZipArchive

      protected void testWithZipArchive(boolean useClasspath) throws ExecutionException
      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 context
      broker - the broker address