コード例 #1
0
ファイル: ManagerTest.java プロジェクト: Squadity/bb-kit
  /**
   * {@link PreDestroy} test.
   *
   * @throws ManagerException
   */
  @Test
  public void preDestroyTest() throws ManagerException {
    // saving initial state
    final int currentValue = SampleServiceImpl.getPreDestroyedAcount();

    Manager.register(SampleService.class, SampleServiceFactory.class);
    Manager.get(SampleService.class); // force initialization
    Manager.tearDown();
    Assert.assertEquals(currentValue + 2, SampleServiceImpl.getPreDestroyedAcount());
  }
コード例 #2
0
ファイル: ManagerTest.java プロジェクト: Squadity/bb-kit
  /** Service configuration module complex test. */
  @Test
  public void complexTest() {
    // checking clean configuration
    try {
      Manager.Features.disable(Feature.AUTO_IMPL_DISCOVERY);
      Manager.get(SampleService.class);
      Assert.fail("Exception shold be thrown before this step.");
    } catch (ManagerException e) {
      Assert.assertTrue(
          "Right exception instance should be there.", e instanceof ConfigurationNotFoundException);
    } finally {
      Manager.Features.enable(Feature.AUTO_IMPL_DISCOVERY);
    }

    // configuring local service
    Manager.register(SampleService.class, SampleServiceFactory.class, LOCAL, SERVICE);

    // defining additional custom scope for remote sample service
    CustomScope customScope = CustomScope.get("SAMPLE");

    // configuring remote service with obtaining trough service locator with custom configuration
    Configuration configuration = Configuration.create();
    configuration.set(SampleServiceRemoteFactory.PARAM_TEST, "configured parameter");
    Manager.register(
        SampleService.class,
        SampleServiceRemoteFactory.class,
        configuration,
        customScope,
        REMOTE,
        SERVICE);

    // checking local service
    try {
      SampleService localInstance = Manager.get(SampleService.class, SERVICE, LOCAL, null);
      Assert.assertTrue(localInstance instanceof SampleServiceImpl);
      Assert.assertEquals("CREATED", localInstance.getCreationMethod());
    } catch (ManagerException e) {
      Assert.fail("No exception should be on this step.");
    } catch (SampleServiceException e) {
      Assert.fail("No exception should be on this step.");
    }

    // checking remote service
    try {
      SampleService remoteInstance =
          Manager.get(SampleService.class, SERVICE, null, customScope, REMOTE);
      Assert.assertTrue(remoteInstance instanceof SampleServiceRemoteImpl);
      Assert.assertEquals(
          "LOCATED. PARAMETER: configured parameter", remoteInstance.getCreationMethod());
    } catch (ManagerException e) {
      Assert.fail("No exception should be on this step.");
    } catch (SampleServiceException e) {
      Assert.fail("No exception should be on this step.");
    }

    // resetting manager configuration
    Manager.tearDown();

    // checking clean configuration, default scope
    try {
      Manager.Features.disable(Feature.AUTO_IMPL_DISCOVERY);
      Manager.get(SampleService.class);
      Assert.fail("Exception shold be thrown before this step.");
    } catch (ManagerException e) {
      Assert.assertTrue(
          "Right exception instance should be there.", e instanceof ConfigurationNotFoundException);
    } finally {
      Manager.Features.enable(Feature.AUTO_IMPL_DISCOVERY);
    }

    // checking clean configuration, local scope
    try {
      Manager.Features.disable(Feature.AUTO_IMPL_DISCOVERY);
      Manager.get(SampleService.class, SERVICE, null, LOCAL);
      Assert.fail("Exception shold be thrown before this step.");
    } catch (ManagerException e) {
      Assert.assertTrue(
          "Right exception instance should be there.", e instanceof ConfigurationNotFoundException);
    } finally {
      Manager.Features.enable(Feature.AUTO_IMPL_DISCOVERY);
    }

    // checking clean configuration, remote scope
    try {
      Manager.Features.disable(Feature.AUTO_IMPL_DISCOVERY);
      Manager.get(SampleService.class, SERVICE, REMOTE, null, customScope);
      Assert.fail("Exception shold be thrown before this step.");
    } catch (ManagerException e) {
      Assert.assertTrue(
          "Right exception instance should be there.", e instanceof ConfigurationNotFoundException);
    } finally {
      Manager.Features.enable(Feature.AUTO_IMPL_DISCOVERY);
    }
  }
コード例 #3
0
ファイル: ManagerTest.java プロジェクト: Squadity/bb-kit
 /** Initialization executed after each test. */
 @After
 public void after() {
   Manager.tearDown();
 }
コード例 #4
0
ファイル: ManagerTest.java プロジェクト: Squadity/bb-kit
 /** Initialization executed before each test. */
 @Before
 public void before() {
   Manager.tearDown();
 }