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

The following examples show how to use org.jboss.as.subsystem.test.KernelServices#shutdown() . 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: JMXSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testParseAndMarshalModelWithRemoteConnectorRef1_1() throws Exception {
    //Parse the subsystem xml and install into the first controller
    String subsystemXml =
            "<subsystem xmlns=\"" + Namespace.JMX_1_1.getUriString() + "\">" +
            "<remoting-connector/> " +
            "</subsystem>";


    AdditionalInitialization additionalInit = new BaseAdditionalInitialization();

    KernelServices servicesA = createKernelServicesBuilder(additionalInit).setSubsystemXml(subsystemXml).build();
    //Get the model and the persisted xml from the first controller
    ModelNode modelA = servicesA.readWholeModel();
    String marshalled = servicesA.getPersistedSubsystemXml();
    servicesA.shutdown();

    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 2
Source File: LoggingSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testConfiguration() throws Exception {
    final KernelServices kernelServices = boot();
    final ModelNode currentModel = getSubsystemModel(kernelServices);
    compare(currentModel, ConfigurationPersistence.getConfigurationPersistence(LogContext.getLogContext()));

    // Compare properties written out to current model
    final String dir = resolveRelativePath(kernelServices, "jboss.server.config.dir");
    Assert.assertNotNull("jboss.server.config.dir could not be resolved", dir);
    final LogContext logContext = LogContext.create();
    final ConfigurationPersistence config = ConfigurationPersistence.getOrCreateConfigurationPersistence(logContext);
    try (final FileInputStream in = new FileInputStream(new File(dir, "logging.properties"))) {
        config.configure(in);
        compare(currentModel, config);
    }

    kernelServices.shutdown();
}
 
Example 3
Source File: HandlerLegacyOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testOperations() throws Exception {
    final KernelServices kernelServices = boot();

    testConsoleHandler(kernelServices, null);
    testConsoleHandler(kernelServices, PROFILE);

    testFileHandler(kernelServices, null);
    testFileHandler(kernelServices, PROFILE);

    testPeriodicRotatingFileHandler(kernelServices, null);
    testPeriodicRotatingFileHandler(kernelServices, PROFILE);

    testSizeRotatingFileHandler(kernelServices, null);
    testPeriodicRotatingFileHandler(kernelServices, PROFILE);

    // Run these last as they put the server in reload-required, and the later
    // ones will not update runtime once that is done
    testAsyncHandler(kernelServices, null);
    testAsyncHandler(kernelServices, PROFILE);

    kernelServices.shutdown();
}
 
Example 4
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 5
Source File: LoggerOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testOperations() throws Exception {
    final KernelServices kernelServices = boot();

    testRootLogger(kernelServices, null);
    testRootLogger(kernelServices, PROFILE);

    testLogger(kernelServices, null);
    testLogger(kernelServices, PROFILE);

    kernelServices.shutdown();
}
 
Example 6
Source File: RootSubsystemOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testAttributes() throws Exception {
    final KernelServices kernelServices = boot();
    final ModelNode address = SUBSYSTEM_ADDRESS.toModelNode();
    testWrite(kernelServices, address, LoggingResourceDefinition.ADD_LOGGING_API_DEPENDENCIES, true);
    testWrite(kernelServices, address, LoggingResourceDefinition.USE_DEPLOYMENT_LOGGING_CONFIG, false);
    testUndefine(kernelServices, address, LoggingResourceDefinition.ADD_LOGGING_API_DEPENDENCIES);
    testUndefine(kernelServices, address, LoggingResourceDefinition.USE_DEPLOYMENT_LOGGING_CONFIG);

    kernelServices.shutdown();
}
 
Example 7
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_0() throws Exception {
    //Parse the subsystem xml and install into the first controller
    String subsystemXml =
            "<subsystem xmlns=\"" + Namespace.JMX_1_0.getUriString() + "\">" +
            "    <jmx-connector registry-binding=\"registry1\" server-binding=\"server1\" />" +
            "</subsystem>";
    String finishedSubsystemXml =
                    "<subsystem xmlns=\"" + Namespace.JMX_1_0.getUriString() + "\"/>";
    AdditionalInitialization additionalInit = new BaseAdditionalInitialization();

    KernelServices servicesA = createKernelServicesBuilder(additionalInit).setSubsystemXml(subsystemXml).build();
    //Get the model and the persisted xml from the first controller
    ModelNode modelA = servicesA.readWholeModel();
    String marshalled = servicesA.getPersistedSubsystemXml();
    servicesA.shutdown();

    Assert.assertTrue(marshalled.contains(Namespace.CURRENT.getUriString()));

    compareXml(null, finishedSubsystemXml, 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 8
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 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 testParseAndMarshallModelWithAuditLogButNoHandlerReferences() 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\"/>" +
            "   <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 10
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 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_3WithShowModels() 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\"/>" +
            "   <expose-expression-model domain-name=\"jboss.EXPRESSION\"/>" +
            "</subsystem>";

    AdditionalInitialization additionalInit = new BaseAdditionalInitialization();

    KernelServices servicesA = createKernelServicesBuilder(additionalInit).setSubsystemXml(subsystemXml).build();
    //Get the model and the persisted xml from the first controller
    ModelNode modelA = servicesA.readWholeModel();
    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: 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 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 testParseAndMarshalModel1_2WithShowModels() 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\"/>" +
            "   <expose-expression-model domain-name=\"jboss.EXPRESSION\"/>" +
            "</subsystem>";

    AdditionalInitialization additionalInit = new BaseAdditionalInitialization();

    KernelServices servicesA = createKernelServicesBuilder(additionalInit).setSubsystemXml(subsystemXml).build();
    //Get the model and the persisted xml from the first controller
    ModelNode modelA = servicesA.readWholeModel();
    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 testParseAndMarshalModel1_1() throws Exception {
    //Parse the subsystem xml and install into the first controller
    String subsystemXml =
            "<subsystem xmlns=\"" + Namespace.JMX_1_1.getUriString() + "\">" +
            "<show-model value=\"true\"/>" +
            "<remoting-connector/>" +
            "</subsystem>";

    String finishedXml =
            "<subsystem xmlns=\"" + Namespace.CURRENT.getUriString() + "\">" +
            "    <expose-resolved-model proper-property-format=\"false\"/>" +
            "    <remoting-connector/>" +
            "</subsystem>";

    AdditionalInitialization additionalInit = new BaseAdditionalInitialization();

    KernelServices servicesA = createKernelServicesBuilder(additionalInit).setSubsystemXml(subsystemXml).build();
    //Get the model and the persisted xml from the first controller
    ModelNode modelA = servicesA.readWholeModel();
    String marshalled = servicesA.getPersistedSubsystemXml();
    servicesA.shutdown();

    Assert.assertTrue(marshalled.contains(Namespace.CURRENT.getUriString()));
    compareXml(null, finishedXml, 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 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 testParseAndMarshalModel1_1WithShowModel() throws Exception {
    //Parse the subsystem xml and install into the first controller
    String subsystemXml =
            "<subsystem xmlns=\"" + Namespace.JMX_1_1.getUriString() + "\">" +
            "<show-model value=\"true\"/>" +
            "</subsystem>";

    String finishedXml =
            "<subsystem xmlns=\"" + Namespace.CURRENT.getUriString() + "\">" +
            "    <expose-resolved-model proper-property-format=\"false\"/>" +
            "</subsystem>";

    AdditionalInitialization additionalInit = new BaseAdditionalInitialization();

    KernelServices servicesA = createKernelServicesBuilder(additionalInit).setSubsystemXml(subsystemXml).build();
    //Get the model and the persisted xml from the first controller
    ModelNode modelA = servicesA.readWholeModel();
    String marshalled = servicesA.getPersistedSubsystemXml();
    servicesA.shutdown();

    Assert.assertTrue(marshalled.contains(Namespace.CURRENT.getUriString()));
    compareXml(null, finishedXml, 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 16
Source File: RootSubsystemOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testLogFileResource() throws Exception {
    final KernelServices kernelServices = boot();

    // Subsystem address
    final ModelNode address = SUBSYSTEM_ADDRESS.append("log-file").toModelNode();
    ModelNode op = SubsystemOperations.createReadResourceOperation(address);
    //op.get("include-runtime").set(true);
    ModelNode result = executeOperation(kernelServices, op);
    List<ModelNode> resources = SubsystemOperations.readResult(result).asList();
    assertFalse("No Resources were found: " + result, resources.isEmpty());

    int expectedSize = resources.size();

    // Add a new file not in the jboss.server.log.dir directory
    final Path logFile = LoggingTestEnvironment.get().getLogDir().resolve("fh.log");
    final ModelNode fhAddress = createFileHandlerAddress("fh").toModelNode();
    op = SubsystemOperations.createAddOperation(fhAddress);
    op.get("file").set(createFileValue(null, logFile.toAbsolutePath().toString()));
    executeOperation(kernelServices, op);

    // Re-read the log-file resource, the size should be the same
    result = executeOperation(kernelServices, SubsystemOperations.createReadResourceOperation(address));
    resources = SubsystemOperations.readResult(result).asList();
    assertEquals("Log file " + logFile + " should not be a resource", expectedSize, resources.size());

    // Change the file path of the file handler which should make it a log-file resource
    op = SubsystemOperations.createWriteAttributeOperation(fhAddress, "file", createFileValue("jboss.server.log.dir", "fh-2.log"));
    executeOperation(kernelServices, op);
    // Should be an additional resource
    result = executeOperation(kernelServices, SubsystemOperations.createReadResourceOperation(address));
    resources = SubsystemOperations.readResult(result).asList();
    assertEquals("Additional log-file resource failed to dynamically get added", ++expectedSize, resources.size());

    // Test the read-log-file on the
    final ModelNode simpleLogAddress = SUBSYSTEM_ADDRESS.append("log-file", "simple.log").toModelNode();
    op = SubsystemOperations.createOperation("read-log-file", simpleLogAddress);
    testReadLogFile(kernelServices, op, getLogger());

    // Test on the logging-profile
    final ModelNode profileAddress = SUBSYSTEM_ADDRESS.append("logging-profile", "testProfile").append("log-file", "profile-simple.log").toModelNode();
    op = SubsystemOperations.createOperation("read-log-file", profileAddress);
    testReadLogFile(kernelServices, op, getLogger("testProfile"));

    // Test file in subdirectory
    final ModelNode subFhAddress = createFileHandlerAddress("sub-fh").toModelNode();
    op = SubsystemOperations.createAddOperation(subFhAddress);
    op.get("file").set(createFileValue("jboss.server.log.dir", "subdir" + File.separator + "sub-fh.log"));
    executeOperation(kernelServices, op);
    result = executeOperation(kernelServices, SubsystemOperations.createReadResourceOperation(address));
    resources = SubsystemOperations.readResult(result).asList();
    assertEquals("Log file " + logFile + " should not be a resource", ++expectedSize, resources.size());

    kernelServices.shutdown();

}
 
Example 17
Source File: RootSubsystemOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
@Deprecated
public void testListLogFiles() throws Exception {
    final KernelServices kernelServices = boot();

    // Subsystem address
    final ModelNode address = SUBSYSTEM_ADDRESS.toModelNode();
    final ModelNode op = SubsystemOperations.createOperation("list-log-files", address);
    ModelNode result = executeOperation(kernelServices, op);
    List<ModelNode> logFiles = SubsystemOperations.readResult(result).asList();

    // Should only be one file
    // TODO (jrp) can be tested when LOGMGR-83 is committed and the logmanager is updated
    // assertEquals("Found: " + logFiles, 2, logFiles.size());

    // Should contain simple.log and simple-profile.log
    boolean found = false;
    boolean foundProfile = false;
    for (ModelNode fileInfo : logFiles) {
        final String fileName = fileInfo.get("file-name").asString();
        if ("simple.log".equals(fileName)) {
            found = true;
        }
        if ("profile-simple.log".equals(fileName)) {
            foundProfile = true;
        }
        if ("ignore.log".equals(fileName)) {
            fail("Found ignore.log, but the file should not be listed.");
        }
        if ("profile-ignore.log".equals(fileName)) {
            fail("Found profile-ignore.log, but the file should not be listed.");
        }
    }
    assertTrue("simple.log file was not found", found);
    assertTrue("profile-simple.log file was not found", foundProfile);

    // Change the permissions on the file so read is not allowed
    final Path file = LoggingTestEnvironment.get().getLogDir().resolve("simple.log");
    // The file should exist
    assertTrue("File does not exist", Files.exists(file));

    // Only test if successfully set
    if (setReadable(file, false)) {
        result = executeOperation(kernelServices, op);
        logFiles = SubsystemOperations.readResult(result).asList();
        // The simple.log should not be in the list
        assertEquals("Read permission was found to be true on the file.", 1, logFiles.size());
        // Reset the file permissions
        assertTrue("Could not reset file permissions", setReadable(file, true));
    }

    kernelServices.shutdown();
}
 
Example 18
Source File: RootSubsystemOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
@Deprecated
public void testReadLogFile() throws Exception {
    final KernelServices kernelServices = boot();

    // Subsystem address
    final ModelNode address = SUBSYSTEM_ADDRESS.toModelNode();
    final ModelNode op = SubsystemOperations.createOperation("read-log-file", address);
    op.get("name").set("simple.log");
    testReadLogFile(kernelServices, op, getLogger());

    // Change the permissions on the file so read is not allowed
    final Path file = LoggingTestEnvironment.get().getLogDir().resolve(op.get("name").asString());
    // The file should exist
    assertTrue("File does not exist", Files.exists(file));


    ModelNode result = null;

    // Only test if successfully set
    if (setReadable(file, false)) {
        result = kernelServices.executeOperation(op);
        assertFalse("Should have failed due to denial of read permissions on the file.", SubsystemOperations.isSuccessfulOutcome(result));
        // Reset the file permissions
        assertTrue("Could not reset file permissions", setReadable(file, true));
    }

    // Should be able to read profile-simple.log, but it should be empty
    op.get("name").set("profile-simple.log");
    result = executeOperation(kernelServices, op);
    final List<String> logLines = SubsystemOperations.readResultAsList(result);
    assertEquals(0, logLines.size());

    // Should not be able to read ignore.log even though the file exists
    op.get("name").set("ignore.log");
    result = kernelServices.executeOperation(op);
    assertFalse("Should have failed due to file not be readable.", SubsystemOperations.isSuccessfulOutcome(result));

    // Should not be able to read ignore.log even though the file exists
    op.get("name").set("profile-ignore.log");
    result = kernelServices.executeOperation(op);
    assertFalse("Should have failed due to file not be readable.", SubsystemOperations.isSuccessfulOutcome(result));

    // Test an invalid file
    op.get("name").set("invalid");
    result = kernelServices.executeOperation(op);
    assertFalse("Should have failed due to invalid file.", SubsystemOperations.isSuccessfulOutcome(result));

    kernelServices.shutdown();
}
 
Example 19
Source File: RootSubsystemOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testFailedLogFile() throws Exception {
    final Path configDir = LoggingTestEnvironment.get().getConfigDir();
    final Path logDir = LoggingTestEnvironment.get().getLogDir();

    // Create the test log file
    final Path logFile = configDir.resolve("test-config.log");

    Files.deleteIfExists(logFile);
    Files.createFile(logFile);
    final Path relativeLogFile = logDir.relativize(logFile);
    assertTrue("Expected the log file log file to exist", Files.exists(logFile));

    final KernelServices kernelServices = boot();

    // Attempt to read an attribute on a valid file, but a non-existing resource
    final ModelNode address = SUBSYSTEM_ADDRESS.append("log-file", relativeLogFile.toString()).toModelNode();
    ModelNode op = SubsystemOperations.createReadAttributeOperation(address, "file-size");
    executeOperationForFailure(kernelServices, op);

    // Attempt to read a valid file on a non-existing resource
    op = SubsystemOperations.createOperation("read-log-file", address);
    executeOperationForFailure(kernelServices, op);

    // Add a valid file-handler
    final ModelNode handlerAddress = createFileHandlerAddress(relativeLogFile.toString()).toModelNode();
    op = SubsystemOperations.createAddOperation(handlerAddress);
    op.get("append").set(true);
    final ModelNode fileModel = op.get("file").setEmptyObject();
    fileModel.get("relative-to").set("jboss.server.log.dir");
    fileModel.get("path").set(relativeLogFile.toString());
    executeOperation(kernelServices, op);

    // Attempt to read an attribute on a valid file handler. The file handler was created in the jboss.server.log.dir
    // however it used a relative path to attempt to allow any file to be read
    op = SubsystemOperations.createReadAttributeOperation(address, "file-size");
    executeOperationForFailure(kernelServices, op);

    // Attempt to read the file on a valid file handler. The file handler was created in the jboss.server.log.dir
    // however it used a relative path to attempt to allow any file to be read
    op = SubsystemOperations.createOperation("read-log-file", address);
    executeOperationForFailure(kernelServices, op);

    kernelServices.shutdown();
}
 
Example 20
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();
}