public void testSimpleLifecycle() throws Exception {
    final String RESOURCE = "/r1";
    final String LIFECYCLE = "simpleLifecycle";

    RegistryContext context = registry.getRegistryContext();
    context.selectDBConfig("h2-db");
    context.addAspect(LIFECYCLE, new SimpleLifecycle(), MultitenantConstants.SUPER_TENANT_ID);

    String[] aspects = registry.getAvailableAspects();
    assertTrue(aspects.length > 0);
    boolean found = false;
    for (String aspect : aspects) {
      if (aspect.equals(LIFECYCLE)) {
        found = true;
      }
    }
    assertTrue("Lifecycle not found in available aspects", found);

    Resource resource = registry.newResource();
    resource.setDescription("My thing");
    registry.put(RESOURCE, resource);

    registry.associateAspect(RESOURCE, LIFECYCLE);

    resource = registry.get(RESOURCE);
    assertNotNull(resource);
    String propValue = resource.getProperty(SimpleLifecycle.STATE_PROP);
    assertNotNull(propValue);
    assertEquals("Wrong initial state!", SimpleLifecycle.INIT, propValue);

    String[] actions = registry.getAspectActions(RESOURCE, LIFECYCLE);
    assertNotNull("No available actions", actions);
    assertEquals("Wrong # of available actions", 1, actions.length);
    assertEquals("Wrong available action", SimpleLifecycle.ACTION, actions[0]);

    registry.invokeAspect(RESOURCE, LIFECYCLE, SimpleLifecycle.ACTION);

    resource = registry.get(RESOURCE);

    // OK, now we should be in the next state
    propValue = resource.getProperty(SimpleLifecycle.STATE_PROP);
    assertNotNull(propValue);
    assertEquals("Wrong state!", SimpleLifecycle.FINAL, propValue);
  }
Example #2
0
  public void setUp() throws RegistryException {
    if (System.getProperty("carbon.home") == null) {
      File file = new File("src/test/resources/carbon-home");
      if (file.exists()) {
        System.setProperty("carbon.home", file.getAbsolutePath());
      }
    }

    // The line below is responsible for initializing the cache.
    CarbonContext.getCurrentContext();

    String carbonHome = System.getProperty("carbon.home");
    System.out.println("carbon home " + carbonHome);
    String carbonXMLPath =
        carbonHome
            + File.separator
            + "repository"
            + File.separator
            + "conf"
            + File.separator
            + "carbon.xml";
    RegistryConfiguration regConfig = new RegistryConfiguration(carbonXMLPath);
    RegistryCoreServiceComponent.setRegistryConfig(regConfig);

    RealmService realmService = new InMemoryRealmService();
    InputStream is;

    try {
      is = this.getClass().getClassLoader().getResourceAsStream("registry.xml");
    } catch (Exception e) {
      is = null;
    }
    ctx = RegistryContext.getBaseInstance(is, realmService);
    // RegistryConfigurationProcessor.populateRegistryConfig(is, ctx);
    ctx.setSetup(true);
    ctx.selectDBConfig("h2-db");
  }