Java Code Examples for org.jboss.as.subsystem.test.KernelServices#readWholeModel()

The following examples show how to use org.jboss.as.subsystem.test.KernelServices#readWholeModel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OtherServicesSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Test that system property got added properly
 */
@Test
public void testSystemProperty() throws Exception {
    ((OtherServicesSubsystemExtension)getMainExtension()).setAddHandler(SubsystemAddBlank.INSTANCE);

    //Parse the subsystem xml and install into the controller
    String subsystemXml =
            "<subsystem xmlns=\"" + SimpleSubsystemExtension.NAMESPACE + "\">" +
            "</subsystem>";
    KernelServices services = createKernelServicesBuilder(new SystemPropertiesInit())
            .setSubsystemXml(subsystemXml)
            .build();

    //Read the whole model and make sure it looks as expected
    ModelNode model = services.readWholeModel();
    Assert.assertTrue(model.get(SUBSYSTEM).hasDefined(OtherServicesSubsystemExtension.SUBSYSTEM_NAME));

    Assert.assertEquals("testing123", model.require(SYSTEM_PROPERTY).require("test123").require(VALUE).asString());
}
 
Example 2
Source File: OtherServicesSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Test that other services got added properly
 */
@Test
public void testOtherService() throws Exception {
    ((OtherServicesSubsystemExtension)getMainExtension()).setAddHandler(SubsystemAddWithOtherService.INSTANCE);

    //Parse the subsystem xml and install into the controller
    String subsystemXml =
            "<subsystem xmlns=\"" + SimpleSubsystemExtension.NAMESPACE + "\">" +
            "</subsystem>";
    KernelServices services = createKernelServicesBuilder(new ExtraServicesInit())
            .setSubsystemXml(subsystemXml)
            .build();

    //Read the whole model and make sure it looks as expected
    ModelNode model = services.readWholeModel();
    Assert.assertTrue(model.get(SUBSYSTEM).hasDefined(OtherServicesSubsystemExtension.SUBSYSTEM_NAME));

    Assert.assertNotNull(services.getContainer().getService(OtherService.NAME));
    Assert.assertNotNull(services.getContainer().getService(MyService.NAME));
    MyService myService = (MyService)services.getContainer().getService(MyService.NAME).getValue();
    Assert.assertNotNull(myService.otherValue.getValue());
}
 
Example 3
Source File: ExtraSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Test that the model created from the xml looks as expected
 */
@Test
public void testInstallIntoController() throws Exception {
    //Parse the subsystem xml and install into the controller
    String subsystemXml =
            "<subsystem xmlns=\"" + DependencySubsystemExtension.NAMESPACE + "\">" +
            "</subsystem>" +
            "<subsystem xmlns=\"" + MainSubsystemExtension.NAMESPACE + "\">" +
            "</subsystem>";
    KernelServices services = createKernelServicesBuilder(new DependencyAdditionalInitialization())
            .setSubsystemXml(subsystemXml)
            .build();

    //Read the whole model and make sure it looks as expected
    ModelNode model = services.readWholeModel();
    Assert.assertTrue(model.get(SUBSYSTEM).hasDefined(DependencySubsystemExtension.SUBSYSTEM_NAME));
    Assert.assertTrue(model.get(SUBSYSTEM).hasDefined(MainSubsystemExtension.SUBSYSTEM_NAME));

    Assert.assertNotNull(services.getContainer().getService(Dependency.NAME));
    Assert.assertNotNull(services.getContainer().getService(MainService.NAME));
    MainService mainService = (MainService)services.getContainer().getService(MainService.NAME).getValue();
    Assert.assertNotNull(mainService.dependencyValue.getValue());

}
 
Example 4
Source File: RemotingLegacySubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testSubsystem12WithConnector() throws Exception {
    KernelServices services = createKernelServicesBuilder(createRuntimeAdditionalInitialization(true))
            .setSubsystemXmlResource("remoting12-with-connector.xml").build();

    ServiceName connectorServiceName = RemotingServices.serverServiceName("test-connector");
    DependenciesRetrievalService dependencies = DependenciesRetrievalService.create(services, connectorServiceName);
    Object connectorService = dependencies.getService(connectorServiceName);
    assertNotNull(connectorService);

    ModelNode model = services.readWholeModel();
    ModelNode subsystem = model.require(SUBSYSTEM).require(RemotingExtension.SUBSYSTEM_NAME);

    ModelNode connector = subsystem.require(CommonAttributes.CONNECTOR).require("test-connector");
    assertEquals(1, connector.require(CommonAttributes.PROPERTY).require("org.xnio.Options.WORKER_ACCEPT_THREADS").require(CommonAttributes.VALUE).asInt());
    // the following 2 attributes are new in remoting 1.2 NS
    assertEquals("myProto", connector.require(CommonAttributes.SASL_PROTOCOL).asString());
    assertEquals("myServer", connector.require(CommonAttributes.SERVER_NAME).asString());

    // Validate the io subsystem was added
    assertTrue(model.require(SUBSYSTEM).hasDefined("io"));
}
 
Example 5
Source File: SimpleSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Test that the model created from the xml looks as expected, and that the services are installed
 */
@Test
public void testInstallIntoController() throws Exception {
    //Parse the subsystem xml and install into the controller
    String subsystemXml =
            "<subsystem xmlns=\"" + SimpleSubsystemExtension.NAMESPACE + "\">" +
            "</subsystem>";
    KernelServices services = createKernelServicesBuilder(null)
            .setSubsystemXml(subsystemXml)
            .build();

    //Read the whole model and make sure it looks as expected
    ModelNode model = services.readWholeModel();
    Assert.assertTrue(model.get(SUBSYSTEM).hasDefined(SimpleSubsystemExtension.SUBSYSTEM_NAME));

    //Test that the service was installed
    services.getContainer().getRequiredService(SimpleService.NAME);

    //Check that all the resources were removed
    super.assertRemoveSubsystemResources(services);
    try {
        services.getContainer().getRequiredService(SimpleService.NAME);
        Assert.fail("Should not have found simple service");
    } catch (Exception expected) {
    }
}
 
Example 6
Source File: JBossSubsystemXMLTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 *  Parses and marshall the given subsystemXmlFile into one controller, then reads the model into second one.
 *  Compares the models afterwards.
 * @param subsystemXmlFile the name of the subsystem xml file
 * @throws Exception
 */
protected void parseAndMarshalSubsystemModelFromFile(String subsystemXmlFile) throws Exception {
  String subsystemXml = FileUtils.readFile(subsystemXmlFile);
  // Parse the subsystem xml and install into the first controller
  KernelServices servicesA = createKernelServicesBuilder(null).setSubsystemXml(subsystemXml).build();
  // Get the model and the persisted xml from the first controller
  ModelNode modelA = servicesA.readWholeModel();
  String marshalled = servicesA.getPersistedSubsystemXml();

  // Make sure the xml is the same
  compareXml(null, subsystemXml, marshalled);

  // Install the persisted xml from the first controller into a second controller
  KernelServices servicesB = createKernelServicesBuilder(null).setSubsystemXml(marshalled).build();
  ModelNode modelB = servicesB.readWholeModel();

  // Make sure the models from the two controllers are identical
  compare(modelA, modelB);
}
 
Example 7
Source File: SimpleSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Tests that we can trigger output of the model, i.e. that outputModel() works as it should
 */
@Test
public void testOutputModel() throws Exception {
    String subsystemXml =
            "<subsystem xmlns=\"" + SimpleSubsystemExtension.NAMESPACE + "\">" +
            "</subsystem>";

    ModelNode testModel = new ModelNode();
    testModel.get(SUBSYSTEM).get(SimpleSubsystemExtension.SUBSYSTEM_NAME).setEmptyObject();
    String triggered = outputModel(testModel);

    KernelServices services = createKernelServicesBuilder(AdditionalInitialization.MANAGEMENT)
            .setSubsystemXml(subsystemXml)
            .build();
    //Get the model and the persisted xml from the controller
    services.readWholeModel();
    String marshalled = services.getPersistedSubsystemXml();

    Assert.assertEquals(marshalled, triggered);
    Assert.assertEquals(normalizeXML(marshalled), normalizeXML(triggered));
}
 
Example 8
Source File: SimpleSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Test that the model created from the xml looks as expected, and that the services are NOT installed
 */
@Test
public void testInstallIntoControllerModelOnly() throws Exception {
    //Parse the subsystem xml and install into the controller
    String subsystemXml =
            "<subsystem xmlns=\"" + SimpleSubsystemExtension.NAMESPACE + "\">" +
            "</subsystem>";
    KernelServices services = createKernelServicesBuilder(AdditionalInitialization.MANAGEMENT)
            .setSubsystemXml(subsystemXml)
            .build();

    //Read the whole model and make sure it looks as expected
    ModelNode model = services.readWholeModel();
    Assert.assertTrue(model.get(SUBSYSTEM).hasDefined(SimpleSubsystemExtension.SUBSYSTEM_NAME));

    //Test that the service was not installed
    Assert.assertNull(services.getContainer().getService(SimpleService.NAME));

    //Check that all the resources were removed
    super.assertRemoveSubsystemResources(services);
    try {
        services.getContainer().getRequiredService(SimpleService.NAME);
        Assert.fail("Should not have found simple service");
    } catch (Exception expected) {
    }
}
 
Example 9
Source File: JMXSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testParseAndMarshalModel1_2WithShowModelsAndOldPropertyFormat() throws Exception {
    //Parse the subsystem xml and install into the first controller
    String subsystemXml =
            "<subsystem xmlns=\"" + Namespace.JMX_1_2.getUriString() + "\">" +
            "   <expose-resolved-model domain-name=\"jboss.RESOLVED\" proper-property-format=\"false\"/>" +
            "   <expose-expression-model domain-name=\"jboss.EXPRESSION\"/>" +
            "</subsystem>";

    AdditionalInitialization additionalInit = new BaseAdditionalInitialization();

    KernelServices servicesA = createKernelServicesBuilder(additionalInit).setSubsystemXml(subsystemXml).build();
    Assert.assertTrue(servicesA.isSuccessfulBoot());
    //Get the model and the persisted xml from the first controller
    ModelNode modelA = servicesA.readWholeModel();
    Assert.assertTrue(modelA.get(SUBSYSTEM, "jmx", CommonAttributes.EXPOSE_MODEL, CommonAttributes.RESOLVED).hasDefined(CommonAttributes.PROPER_PROPERTY_FORMAT));
    Assert.assertFalse(modelA.get(SUBSYSTEM, "jmx", CommonAttributes.EXPOSE_MODEL, CommonAttributes.RESOLVED, CommonAttributes.PROPER_PROPERTY_FORMAT).asBoolean());
    String marshalled = servicesA.getPersistedSubsystemXml();
    servicesA.shutdown();

    Assert.assertTrue(marshalled.contains(Namespace.CURRENT.getUriString()));
    compareXml(null, subsystemXml, marshalled, true);

    //Install the persisted xml from the first controller into a second controller
    KernelServices servicesB = createKernelServicesBuilder(additionalInit).setSubsystemXml(marshalled).build();
    ModelNode modelB = servicesB.readWholeModel();

    //Make sure the models from the two controllers are identical
    super.compare(modelA, modelB);
}
 
Example 10
Source File: SimpleSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Starts a controller with the given subsystem xml and then checks that a second
 * controller started with the operations from its describe action results in the same model
 */
@Test
public void testDescribeHandler() throws Exception {
    //Parse the subsystem xml and install into the first controller
    String subsystemXml =
            "<subsystem xmlns=\"" + SimpleSubsystemExtension.NAMESPACE + "\">" +
            "</subsystem>";
    KernelServices servicesA = createKernelServicesBuilder(null)
            .setSubsystemXml(subsystemXml)
            .build();
    //Get the model and the describe operations from the first controller
    ModelNode modelA = servicesA.readWholeModel();
    ModelNode describeOp = new ModelNode();
    describeOp.get(OP).set(DESCRIBE);
    describeOp.get(OP_ADDR).set(
            PathAddress.pathAddress(
                    PathElement.pathElement(SUBSYSTEM, SimpleSubsystemExtension.SUBSYSTEM_NAME)).toModelNode());
    List<ModelNode> operations = checkResultAndGetContents(servicesA.executeOperation(describeOp)).asList();


    //Install the describe options from the first controller into a second controller
    KernelServices servicesB = createKernelServicesBuilder(null)
            .setBootOperations(operations)
            .build();
    ModelNode modelB = servicesB.readWholeModel();

    //Make sure the models from the two controllers are identical
    super.compare(modelA, modelB);
}
 
Example 11
Source File: JMXSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testParseAndMarshalModel1_3WithShowModelsAndOldPropertyFormat() throws Exception {
    //Parse the subsystem xml and install into the first controller
    String subsystemXml =
            "<subsystem xmlns=\"" + Namespace.JMX_1_3.getUriString() + "\">" +
            "   <expose-resolved-model domain-name=\"jboss.RESOLVED\" proper-property-format=\"false\"/>" +
            "   <expose-expression-model domain-name=\"jboss.EXPRESSION\"/>" +
            "   <sensitivity non-core-mbeans=\"true\"/>" +
            "</subsystem>";

    AdditionalInitialization additionalInit = new BaseAdditionalInitialization();

    KernelServices servicesA = createKernelServicesBuilder(additionalInit).setSubsystemXml(subsystemXml).build();
    Assert.assertTrue(servicesA.isSuccessfulBoot());
    //Get the model and the persisted xml from the first controller
    ModelNode modelA = servicesA.readWholeModel();
    Assert.assertTrue(modelA.get(SUBSYSTEM, "jmx", CommonAttributes.EXPOSE_MODEL, CommonAttributes.RESOLVED).hasDefined(CommonAttributes.PROPER_PROPERTY_FORMAT));
    Assert.assertFalse(modelA.get(SUBSYSTEM, "jmx", CommonAttributes.EXPOSE_MODEL, CommonAttributes.RESOLVED, CommonAttributes.PROPER_PROPERTY_FORMAT).asBoolean());
    String marshalled = servicesA.getPersistedSubsystemXml();
    servicesA.shutdown();

    Assert.assertTrue(marshalled.contains(Namespace.CURRENT.getUriString()));
    compareXml(null, subsystemXml, marshalled, true);

    //Install the persisted xml from the first controller into a second controller
    KernelServices servicesB = createKernelServicesBuilder(additionalInit).setSubsystemXml(marshalled).build();
    ModelNode modelB = servicesB.readWholeModel();

    //Make sure the models from the two controllers are identical
    super.compare(modelA, modelB);
}
 
Example 12
Source File: OtherServicesSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Test that paths got added properly
 */
@Test
public void testPath() throws Exception {
    ((OtherServicesSubsystemExtension)getMainExtension()).setAddHandler(SubsystemAddWithPathUserService.INSTANCE);

    //Parse the subsystem xml and install into the controller
    String subsystemXml =
            "<subsystem xmlns=\"" + SimpleSubsystemExtension.NAMESPACE + "\">" +
            "</subsystem>";
    KernelServices services = createKernelServicesBuilder(new PathInit())
            .setSubsystemXml(subsystemXml)
            .build();

    //Read the whole model and make sure it looks as expected
    ModelNode model = services.readWholeModel();
    Assert.assertTrue(model.get(SUBSYSTEM).hasDefined(OtherServicesSubsystemExtension.SUBSYSTEM_NAME));

    ModelNode path = model.require(PATH);
    Assert.assertEquals(2, path.asList().size());
    Assert.assertEquals("p1", path.require("p1").require("name").asString());
    Assert.assertEquals(new File(".").getAbsolutePath(), path.require("p1").require("path").asString());
    Assert.assertFalse(path.get("p1", "relative-to").isDefined());
    Assert.assertEquals("p2", path.require("p2").require("name").asString());
    Assert.assertEquals("target", path.require("p2").require("path").asString());
    Assert.assertEquals("p1", path.require("p2").require("relative-to").asString());

    ServiceController<?> controller = services.getContainer().getService(PathUserService.NAME);
    Assert.assertNotNull(controller);
    PathUserService service = (PathUserService)controller.getValue();
    Assert.assertEquals(new File(".", "target").getAbsolutePath(), service.pathValue.getValue());
}
 
Example 13
Source File: JMXSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testParseAndMarshallModelWithAuditLogAndHandlerReferences() throws Exception {
    String subsystemXml =
            "<subsystem xmlns=\"" + Namespace.CURRENT.getUriString() + "\">" +
            "   <expose-resolved-model domain-name=\"jboss.RESOLVED\" proper-property-format=\"false\"/>" +
            "   <expose-expression-model domain-name=\"jboss.EXPRESSION\"/>" +
            "   <audit-log log-boot=\"true\" log-read-only=\"false\" enabled=\"false\">" +
            "       <handlers>" +
            "               <handler name=\"test\"/>" +
            "       </handlers>" +
            "   </audit-log>" +
            "</subsystem>";

    AdditionalInitialization additionalInit = new AuditLogInitialization();

    KernelServices servicesA = createKernelServicesBuilder(additionalInit).setSubsystemXml(subsystemXml).build();
    Assert.assertTrue(servicesA.isSuccessfulBoot());
    //Get the model and the persisted xml from the first controller
    ModelNode modelA = servicesA.readWholeModel();
    Assert.assertTrue(modelA.get(SUBSYSTEM, "jmx", CommonAttributes.EXPOSE_MODEL, CommonAttributes.RESOLVED).hasDefined(CommonAttributes.PROPER_PROPERTY_FORMAT));
    Assert.assertFalse(modelA.get(SUBSYSTEM, "jmx", CommonAttributes.EXPOSE_MODEL, CommonAttributes.RESOLVED, CommonAttributes.PROPER_PROPERTY_FORMAT).asBoolean());
    String marshalled = servicesA.getPersistedSubsystemXml();
    servicesA.shutdown();

    Assert.assertTrue(marshalled.contains(Namespace.CURRENT.getUriString()));
    compareXml(null, subsystemXml, marshalled, true);

    //Install the persisted xml from the first controller into a second controller
    KernelServices servicesB = createKernelServicesBuilder(additionalInit).setSubsystemXml(marshalled).build();
    ModelNode modelB = servicesB.readWholeModel();

    //Make sure the models from the two controllers are identical
    super.compare(modelA, modelB);
}
 
Example 14
Source File: JMXSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testDescribeHandler() throws Exception {
    //Parse the subsystem xml and install into the first controller
    String subsystemXml =
            "<subsystem xmlns=\"" + Namespace.CURRENT.getUriString() + "\">" +
            "   <expose-resolved-model domain-name=\"jboss.RESOLVED\"/>" +
            "   <expose-expression-model domain-name=\"jboss.EXPRESSION\"/>" +
            "   <remoting-connector />" +
            "</subsystem>";
    AdditionalInitialization additionalInit = new BaseAdditionalInitialization();
    KernelServices servicesA = createKernelServicesBuilder(additionalInit).setSubsystemXml(subsystemXml).build();
    //Get the model and the describe operations from the first controller
    ModelNode modelA = servicesA.readWholeModel();
    ModelNode describeOp = new ModelNode();
    describeOp.get(OP).set(DESCRIBE);
    describeOp.get(OP_ADDR).set(
            PathAddress.pathAddress(
                    PathElement.pathElement(SUBSYSTEM, JMXExtension.SUBSYSTEM_NAME)).toModelNode());
    List<ModelNode> operations = checkResultAndGetContents(servicesA.executeOperation(describeOp)).asList();
    servicesA.shutdown();

    Assert.assertEquals(4, operations.size());


    //Install the describe options from the first controller into a second controller
    KernelServices servicesB = createKernelServicesBuilder(additionalInit).setBootOperations(operations).build();
    ModelNode modelB = servicesB.readWholeModel();

    //Make sure the models from the two controllers are identical
    super.compare(modelA, modelB);
}
 
Example 15
Source File: JMXSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testShowModelAlias() throws Exception {
    String subsystemXml =
            "<subsystem xmlns=\"" + Namespace.CURRENT.getUriString() + "\"/>";

    KernelServices services = createKernelServicesBuilder(null).setSubsystemXml(subsystemXml).build();

    ModelNode model = services.readWholeModel();
    Assert.assertFalse(model.get(SUBSYSTEM, JMXExtension.SUBSYSTEM_NAME, CommonAttributes.EXPOSE_MODEL, CommonAttributes.RESOLVED).isDefined());

    ModelNode read = createOperation(READ_ATTRIBUTE_OPERATION);
    read.get(NAME).set(CommonAttributes.SHOW_MODEL);
    Assert.assertFalse(services.executeForResult(read).asBoolean());

    ModelNode write = createOperation(WRITE_ATTRIBUTE_OPERATION);
    write.get(NAME).set(CommonAttributes.SHOW_MODEL);
    write.get(VALUE).set(true);
    services.executeForResult(write);

    model = services.readWholeModel();
    Assert.assertTrue(model.get(SUBSYSTEM, JMXExtension.SUBSYSTEM_NAME, CommonAttributes.EXPOSE_MODEL, CommonAttributes.RESOLVED).isDefined());
    Assert.assertTrue(services.executeForResult(read).asBoolean());

    write.get(VALUE).set(false);
    services.executeForResult(write);

    model = services.readWholeModel();
    Assert.assertFalse(model.get(SUBSYSTEM, JMXExtension.SUBSYSTEM_NAME, CommonAttributes.EXPOSE_MODEL, CommonAttributes.RESOLVED).isDefined());
    Assert.assertFalse(services.executeForResult(read).asBoolean());
}
 
Example 16
Source File: ExtraSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Starts a controller with a given subsystem xml and then checks that a second
 * controller started with the xml marshalled from the first one results in the same model
 */
@Test
public void testParseAndMarshalModel() throws Exception {
    //Parse the subsystem xml and install into the first controller
    String subsystemXml =
            "<subsystem xmlns=\"" + DependencySubsystemExtension.NAMESPACE + "\">" +
            "</subsystem>" +
            "<subsystem xmlns=\"" + MainSubsystemExtension.NAMESPACE + "\">" +
            "</subsystem>";
    KernelServices servicesA = createKernelServicesBuilder(new DependencyAdditionalInitialization())
            .setSubsystemXml(subsystemXml)
            .build();
    //Get the model and the persisted xml from the first controller
    ModelNode modelA = servicesA.readWholeModel();
    String marshalled = servicesA.getPersistedSubsystemXml();
    marshalled = "<subsystem xmlns=\"" + DependencySubsystemExtension.NAMESPACE + "\">" +
            "</subsystem>" + marshalled;

    //Install the persisted xml from the first controller into a second controller
    KernelServices servicesB = createKernelServicesBuilder(new DependencyAdditionalInitialization())
            .setSubsystemXml(marshalled)
            .build();
    ModelNode modelB = servicesB.readWholeModel();

    //Make sure the models from the two controllers are identical
    super.compare(modelA, modelB);
}
 
Example 17
Source File: ExtraSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Starts a controller with the given subsystem xml and then checks that a second
 * controller started with the operations from its describe action results in the same model
 */
@Test
public void testDescribeHandler() throws Exception {
    //Parse the subsystem xml and install into the first controller
    String subsystemXml =
            "<subsystem xmlns=\"" + DependencySubsystemExtension.NAMESPACE + "\">" +
            "</subsystem>" +
            "<subsystem xmlns=\"" + MainSubsystemExtension.NAMESPACE + "\">" +
            "</subsystem>";
    KernelServices servicesA = createKernelServicesBuilder(new DependencyAdditionalInitialization())
            .setSubsystemXml(subsystemXml)
            .build();
    //Get the model and the describe operations from the first controller
    ModelNode modelA = servicesA.readWholeModel();
    ModelNode describeOp = new ModelNode();
    describeOp.get(OP).set(DESCRIBE);
    describeOp.get(OP_ADDR).set(
            PathAddress.pathAddress(
                    PathElement.pathElement(SUBSYSTEM, DependencySubsystemExtension.SUBSYSTEM_NAME)).toModelNode());
    ArrayList<ModelNode> allOps = new ArrayList<>();
    allOps.addAll(checkResultAndGetContents(servicesA.executeOperation(describeOp)).asList());
    describeOp.get(OP_ADDR).set(
            PathAddress.pathAddress(
                    PathElement.pathElement(SUBSYSTEM, MainSubsystemExtension.SUBSYSTEM_NAME)).toModelNode());
    allOps.addAll(checkResultAndGetContents(servicesA.executeOperation(describeOp)).asList());


    //Install the describe options from the first controller into a second controller
    KernelServices servicesB = createKernelServicesBuilder(new DependencyAdditionalInitialization())
            .setBootOperations(allOps)
            .build();
    ModelNode modelB = servicesB.readWholeModel();

    //Make sure the models from the two controllers are identical
    super.compare(modelA, modelB);

}
 
Example 18
Source File: TransformerSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void testTransformers(ModelTestControllerVersion controllerVersion) throws Exception {
    ModelVersion oldVersion = ModelVersion.create(1, 0, 0);
    KernelServicesBuilder builder = createKernelServicesBuilder(null)
            .setSubsystemXml(getSubsystemXml());
    builder.createLegacyKernelServicesBuilder(null, controllerVersion, oldVersion)
            .setExtensionClassName(VersionedExtension1.class.getName())
            .addSimpleResourceURL(LEGACY_ARCHIVE.toString())
            .skipReverseControllerCheck();
    KernelServices mainServices = builder.build();
    KernelServices legacyServices = mainServices.getLegacyServices(oldVersion);
    Assert.assertNotNull(legacyServices);


    ModelNode mainModel = mainServices.readWholeModel();
    ModelNode mainSubsystem = mainModel.get(SUBSYSTEM, "test-subsystem");
    Assert.assertEquals(3, mainSubsystem.keys().size());
    Assert.assertEquals("This is only a test", mainSubsystem.get("test-attribute").asString());
    Assert.assertTrue(mainSubsystem.hasDefined("new-element"));
    Assert.assertTrue(mainSubsystem.get("new-element").hasDefined("test"));
    Assert.assertTrue(mainSubsystem.hasDefined("renamed"));
    Assert.assertTrue(mainSubsystem.get("renamed").hasDefined("element"));

    ModelNode legacyModel = legacyServices.readWholeModel();
    ModelNode legacySubsystem = legacyModel.get(SUBSYSTEM, "test-subsystem");
    Assert.assertEquals(2, legacySubsystem.keys().size());
    Assert.assertEquals("This is only a test", legacySubsystem.get("test-attribute").asString());
    Assert.assertTrue(legacySubsystem.hasDefined("element"));
    Assert.assertTrue(legacySubsystem.get("element").hasDefined("renamed"));

    checkSubsystemModelTransformation(mainServices, oldVersion);

    PathAddress subsystemAddress = PathAddress.pathAddress(SUBSYSTEM, "test-subsystem");
    ModelNode writeAttribute = Util.getWriteAttributeOperation(subsystemAddress, "test-attribute", "do reject");
    OperationTransformer.TransformedOperation op = mainServices.executeInMainAndGetTheTransformedOperation(writeAttribute, oldVersion);
    Assert.assertFalse(op.rejectOperation(success()));

    //The model now has the 'magic' old value which gets put into the transformer attachment, which the reject transformer
    //will reject
    writeAttribute = Util.getWriteAttributeOperation(subsystemAddress, "test-attribute", "something else");
    op = mainServices.executeInMainAndGetTheTransformedOperation(writeAttribute, oldVersion);
    Assert.assertTrue(op.rejectOperation(success()));
    legacyServices.shutdown();
    mainServices.shutdown();
}
 
Example 19
Source File: TransformerAttachmentAndInspectModelSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testTransformers() throws Exception {
    ModelVersion oldVersion = ModelVersion.create(1, 0, 0);
    KernelServicesBuilder builder = createKernelServicesBuilder(null)
            .setSubsystemXml(getSubsystemXml());
    builder.createLegacyKernelServicesBuilder(null, ModelTestControllerVersion.MASTER, oldVersion)
            .setExtensionClassName(OldExtension.class.getName())
            .addSimpleResourceURL("target/legacy-archive.jar")
            .dontPersistXml()//don't test xml persistence as woodstox parser for legacy test will break it
            .skipReverseControllerCheck();
    KernelServices mainServices = builder.build();
    KernelServices legacyServices = mainServices.getLegacyServices(oldVersion);
    Assert.assertNotNull(legacyServices);


    ModelNode mainModel = mainServices.readWholeModel();
    ModelNode legacyModel = legacyServices.readWholeModel();
    checkModels(mainModel, legacyModel, "Hello", "one", "A", "two", "B");

    //Check the resource transformation results in the same model as the one from the add ops
    Assert.assertEquals(legacyModel.get(SUBSYSTEM, "test-subsystem"), mainServices.readTransformedModel(oldVersion).get(SUBSYSTEM, "test-subsystem"));

    //Remove, change, and add things back to the normal state
    final PathAddress subsystemAddress = PathAddress.pathAddress(SUBSYSTEM, "test-subsystem");

    ModelNode write1 = getMapRemoveOperation(subsystemAddress, "properties", "one");
    transformAndExecuteInLegacyController(mainServices, oldVersion, write1);
    checkModels(mainServices.readWholeModel(), legacyServices.readWholeModel(), "Hello", "two", "B");

    ModelNode write2 = getMapPutOperation(subsystemAddress, "properties", "two", "b");
    transformAndExecuteInLegacyController(mainServices, oldVersion, write2);
    checkModels(mainServices.readWholeModel(), legacyServices.readWholeModel(), "Hello", "two", "b");

    ModelNode write3 = getMapRemoveOperation(subsystemAddress, "properties", "two");
    transformAndExecuteInLegacyController(mainServices, oldVersion, write3);
    checkModels(mainServices.readWholeModel(), legacyServices.readWholeModel(), "Hello");

    ModelNode write4 = getMapPutOperation(subsystemAddress, "properties", "one", "A");
    transformAndExecuteInLegacyController(mainServices, oldVersion, write4);
    checkModels(mainServices.readWholeModel(), legacyServices.readWholeModel(), "Hello", "one", "A");

    ModelNode write5 = getMapPutOperation(subsystemAddress, "properties", "two", "B");
    transformAndExecuteInLegacyController(mainServices, oldVersion, write5);
    checkModels(mainServices.readWholeModel(), legacyServices.readWholeModel(), "Hello", "one", "A", "two", "B");

    //Now try to do the same with a composite
    ModelNode composite = Util.createEmptyOperation(COMPOSITE, PathAddress.EMPTY_ADDRESS);
    composite.get(STEPS).add(write1);
    composite.get(STEPS).add(write2);
    composite.get(STEPS).add(write3);
    transformAndExecuteInLegacyController(mainServices, oldVersion, composite);
    checkModels(mainServices.readWholeModel(), legacyServices.readWholeModel(), "Hello");

    composite = Util.createEmptyOperation(COMPOSITE, PathAddress.EMPTY_ADDRESS);
    composite.get(STEPS).add(write4);
    composite.get(STEPS).add(write5);
    transformAndExecuteInLegacyController(mainServices, oldVersion, composite);
    checkModels(mainServices.readWholeModel(), legacyServices.readWholeModel(), "Hello", "one", "A", "two", "B");
    legacyServices.shutdown();
    mainServices.shutdown();
}
 
Example 20
Source File: JMXSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testInstallIntoController() throws Exception {
    //Parse the subsystem xml and install into the controller
    String subsystemXml =
            "<subsystem xmlns=\"" + Namespace.CURRENT.getUriString() + "\">" +
            "<remoting-connector/>" +
            "</subsystem>";
    KernelServices services = createKernelServicesBuilder(new BaseAdditionalInitialization())
            .setSubsystemXml(subsystemXml)
            .build();

    Assert.assertTrue(services.isSuccessfulBoot());

    //Read the whole model and make sure it looks as expected
    ModelNode model = services.readWholeModel();
    Assert.assertTrue(model.get(SUBSYSTEM).hasDefined(JMXExtension.SUBSYSTEM_NAME));

    //Make sure that we can connect to the MBean server
    String urlString = System.getProperty("jmx.service.url",
        "service:jmx:remoting-jmx://localhost:" + JMX_PORT);
    JMXServiceURL serviceURL = new JMXServiceURL(urlString);

    JMXConnector connector = null;
    try {
        MBeanServerConnection connection = null;
        long end = System.currentTimeMillis() + 10000;
        do {
            try {
                connector = JMXConnectorFactory.connect(serviceURL, null);
                connection = connector.getMBeanServerConnection();
            } catch (Exception e) {
                e.printStackTrace();
                Thread.sleep(500);
            }
        } while (connection == null && System.currentTimeMillis() < end);
        Assert.assertNotNull(connection);
        connection.getMBeanCount();
    } finally {
        IoUtils.safeClose(connector);
    }

    super.assertRemoveSubsystemResources(services);
}