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

The following examples show how to use org.jboss.as.subsystem.test.KernelServices#executeOperation() . 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: IdentityOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testDeleteIdentity() throws Exception {
    KernelServices services = createKernelServicesBuilder(null)
            .setSubsystemXmlResource("identity-management.xml")
            .build();
    String principalName = "plainUser";
    PathAddress realmAddress = getSecurityRealmAddress("FileSystemRealm");
    ModelNode operation = createAddIdentityOperation(realmAddress, principalName);
    ModelNode result = services.executeOperation(operation);
    assertSuccessful(result);

    operation = createReadIdentityOperation(realmAddress, principalName);
    result = services.executeOperation(operation);
    assertSuccessful(result);

    operation = createRemoveIdentityOperation(realmAddress, principalName);
    result = services.executeOperation(operation);
    assertSuccessful(result);

    operation = createReadIdentityOperation(realmAddress, principalName);
    result = services.executeOperation(operation);
    assertFail(result);
}
 
Example 2
Source File: IOSubsystem11TestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testRuntime() throws Exception {
    KernelServicesBuilder builder = createKernelServicesBuilder(createAdditionalInitialization())
            .setSubsystemXml(getSubsystemXml());
    KernelServices mainServices = builder.build();
    if (!mainServices.isSuccessfulBoot()) {
        Assert.fail(mainServices.getBootError().toString());
    }
    ServiceController<XnioWorker> workerServiceController = (ServiceController<XnioWorker>) mainServices.getContainer().getService(IOServices.WORKER.append("default"));
    workerServiceController.setMode(ServiceController.Mode.ACTIVE);
    workerServiceController.awaitValue();
    XnioWorker worker = workerServiceController.getService().getValue();
    Assert.assertEquals(ProcessorInfo.availableProcessors() * 2, worker.getIoThreadCount());
    Assert.assertEquals(ProcessorInfo.availableProcessors() * 16, worker.getOption(Options.WORKER_TASK_MAX_THREADS).intValue());
    PathAddress addr = PathAddress.parseCLIStyleAddress("/subsystem=io/worker=default");
    ModelNode op = Util.createOperation("read-resource", addr);
    op.get("include-runtime").set(true);
    mainServices.executeOperation(op);
}
 
Example 3
Source File: IdentityOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testOneTimePassword() throws Exception {
    KernelServices services = createKernelServicesBuilder(null)
            .setSubsystemXmlResource("identity-management.xml")
            .build();
    String principalName = "plainUser";
    PathAddress realmAddress = getSecurityRealmAddress("FileSystemRealm");
    ModelNode operation = createAddIdentityOperation(realmAddress, principalName);
    ModelNode result = services.executeOperation(operation);
    assertSuccessful(result);

    operation = createSetPasswordOperation("default", realmAddress, principalName,
            ModifiableRealmDecorator.SetPasswordHandler.OTPassword.OBJECT_DEFINITION, "pass123", null, null, "Elytron Realm", OneTimePassword.ALGORITHM_OTP_MD5, "fghi", 123);

    result = services.executeOperation(operation);
    assertSuccessful(result);
}
 
Example 4
Source File: IdentityOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testDigestPassword() throws Exception {
    KernelServices services = createKernelServicesBuilder(null)
            .setSubsystemXmlResource("identity-management.xml")
            .build();
    String principalName = "plainUser";
    PathAddress realmAddress = getSecurityRealmAddress("FileSystemRealm");
    ModelNode operation = createAddIdentityOperation(realmAddress, principalName);
    ModelNode result = services.executeOperation(operation);
    assertSuccessful(result);

    operation = createSetPasswordOperation("default", realmAddress, principalName,
            ModifiableRealmDecorator.SetPasswordHandler.Digest.OBJECT_DEFINITION, "digestPassword", null, null, "Elytron Realm", DigestPassword.ALGORITHM_DIGEST_MD5, null, null);

    result = services.executeOperation(operation);
    assertSuccessful(result);
}
 
Example 5
Source File: IOSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testThreadPoolAttrPropagation() throws Exception {
    KernelServices kernelServices = startKernelServices(getSubsystemXml());
    startXnioWorker(kernelServices);

    int coreThreads = 4; // default = 2
    int maxThreads = 64; // default = 128
    int keepAliveMillis = 5000; // default = 100 (0 in seconds)
    PathAddress addr = PathAddress.parseCLIStyleAddress("/subsystem=io/worker=default");
    ModelNode maxThreadsOp = Util.getWriteAttributeOperation(addr, Constants.WORKER_TASK_MAX_THREADS, maxThreads);
    ModelNode coreThreadsOp = Util.getWriteAttributeOperation(addr, Constants.WORKER_TASK_CORE_THREADS, coreThreads);
    ModelNode keepAliveOp = Util.getWriteAttributeOperation(addr, Constants.WORKER_TASK_KEEPALIVE, keepAliveMillis);

    kernelServices.executeOperation(maxThreadsOp);
    kernelServices.executeOperation(coreThreadsOp);
    kernelServices.executeOperation(keepAliveOp);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName threadPoolName = new ObjectName("jboss.threads:name=\"default\",type=thread-pool");
    Assert.assertEquals(coreThreads, (int) mbs.getAttribute(threadPoolName, "CorePoolSize"));
    Assert.assertEquals(maxThreads, (int) mbs.getAttribute(threadPoolName, "MaximumPoolSize"));
    Assert.assertEquals(keepAliveMillis / 1000, (long) mbs.getAttribute(threadPoolName, "KeepAliveTimeSeconds"));
}
 
Example 6
Source File: IdentityOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testSimpleDigestPassword() throws Exception {
    KernelServices services = createKernelServicesBuilder(null)
            .setSubsystemXmlResource("identity-management.xml")
            .build();
    String principalName = "plainUser";
    PathAddress realmAddress = getSecurityRealmAddress("FileSystemRealm");
    ModelNode operation = createAddIdentityOperation(realmAddress, principalName);
    ModelNode result = services.executeOperation(operation);
    assertSuccessful(result);

    operation = createSetPasswordOperation("default", realmAddress, principalName,
            ModifiableRealmDecorator.SetPasswordHandler.SimpleDigest.OBJECT_DEFINITION, "simpleDigest", null, null, null, SimpleDigestPassword.ALGORITHM_SIMPLE_DIGEST_SHA_1, null, null);
    result = services.executeOperation(operation);
    assertSuccessful(result);
}
 
Example 7
Source File: IdentityOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testBcryptPassword() throws Exception {
    KernelServices services = createKernelServicesBuilder(null)
            .setSubsystemXmlResource("identity-management.xml")
            .build();
    String principalName = "plainUser";
    PathAddress realmAddress = getSecurityRealmAddress("FileSystemRealm");
    ModelNode operation = createAddIdentityOperation(realmAddress, principalName);
    ModelNode result = services.executeOperation(operation);
    assertSuccessful(result);

    byte[] salt = generateRandomSalt(BCryptPassword.BCRYPT_SALT_SIZE);

    operation = createSetPasswordOperation("default", realmAddress, principalName,
            ModifiableRealmDecorator.SetPasswordHandler.Bcrypt.OBJECT_DEFINITION, "bcryptPassword", salt, 10, null, null, null, null);
    result = services.executeOperation(operation);
    assertSuccessful(result);
}
 
Example 8
Source File: IdentityOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testReadIdentity() throws Exception {
    KernelServices services = createKernelServicesBuilder(null)
            .setSubsystemXmlResource("identity-management.xml")
            .build();
    String principalName = "plainUser";
    PathAddress realmAddress = getSecurityRealmAddress("FileSystemRealm");
    ModelNode operation = createAddIdentityOperation(realmAddress, principalName);
    ModelNode result = services.executeOperation(operation);
    assertSuccessful(result);

    operation = createReadIdentityOperation(realmAddress, principalName);
    result = services.executeOperation(operation);
    assertSuccessful(result);

    ModelNode resultNode = result.get(RESULT);

    assertEquals(principalName, resultNode.get(NAME).asString());
    assertFalse(resultNode.get(ATTRIBUTES).isDefined());
    assertFalse(resultNode.get(ROLES).isDefined());
}
 
Example 9
Source File: IOSubsystem20TestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testRuntime() throws Exception {
    KernelServicesBuilder builder = createKernelServicesBuilder(createAdditionalInitialization())
            .setSubsystemXml(getSubsystemXml());
    KernelServices mainServices = builder.build();
    if (!mainServices.isSuccessfulBoot()) {
        Assert.fail(String.valueOf(mainServices.getBootError()));
    }
    ServiceController<XnioWorker> workerServiceController = (ServiceController<XnioWorker>) mainServices.getContainer().getService(IOServices.WORKER.append("default"));
    workerServiceController.setMode(ServiceController.Mode.ACTIVE);
    workerServiceController.awaitValue();
    XnioWorker worker = workerServiceController.getService().getValue();
    Assert.assertEquals(ProcessorInfo.availableProcessors() * 2, worker.getIoThreadCount());
    Assert.assertEquals(ProcessorInfo.availableProcessors() * 16, worker.getOption(Options.WORKER_TASK_MAX_THREADS).intValue());
    PathAddress addr = PathAddress.parseCLIStyleAddress("/subsystem=io/worker=default");
    ModelNode op = Util.createOperation("read-resource", addr);
    op.get("include-runtime").set(true);
    mainServices.executeOperation(op);
}
 
Example 10
Source File: RemotingSubsystemTransformersTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void checkReject(ModelNode operation, KernelServices mainServices, ModelVersion version) throws OperationFailedException {

        ModelNode mainResult = mainServices.executeOperation(operation);
        assertEquals(mainResult.toJSONString(true), SUCCESS, mainResult.get(OUTCOME).asString());

        final OperationTransformer.TransformedOperation op = mainServices.transformOperation(version, operation);
        final ModelNode result = mainServices.executeOperation(version, op);
        assertEquals("should reject the operation", FAILED, result.get(OUTCOME).asString());
    }
 
Example 11
Source File: IdentityOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testAddEmptyAttributeValue() throws Exception {
    KernelServices services = createKernelServicesBuilder(null)
            .setSubsystemXmlResource("identity-management.xml")
            .build();
    String principalName = "plainUser";
    PathAddress realmAddress = getSecurityRealmAddress("FileSystemRealm");
    ModelNode operation = createAddIdentityOperation(realmAddress, principalName);
    ModelNode result = services.executeOperation(operation);

    assertSuccessful(result);

    operation = createAddAttributeOperation(realmAddress, principalName, "name", "John Smith");
    result = services.executeOperation(operation);
    assertSuccessful(result);

    operation = createAddAttributeOperation(realmAddress, principalName, "phoneNumber", "");
    result = services.executeOperation(operation);
    assertSuccessful(result);

    operation = createReadIdentityOperation(realmAddress, principalName);
    result = services.executeOperation(operation);
    assertSuccessful(result);

    ModelNode resultNode = result.get(RESULT);
    ModelNode attributesNode = resultNode.get(ATTRIBUTES);

    assertTrue(attributesNode.isDefined());
    assertAttributeValue(attributesNode, "name", "John Smith");
    assertAttributeValue(attributesNode, "phoneNumber", "");
}
 
Example 12
Source File: AbstractLoggingSubsystemTest.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static String resolveRelativePath(final KernelServices kernelServices, final String relativeTo) {
    final PathAddress address = PathAddress.pathAddress(PathElement.pathElement(ClientConstants.PATH, relativeTo));
    final ModelNode op = SubsystemOperations.createReadAttributeOperation(address.toModelNode(), ClientConstants.PATH);
    final ModelNode result = kernelServices.executeOperation(op);
    if (SubsystemOperations.isSuccessfulOutcome(result)) {
        return SubsystemOperations.readResultAsString(result);
    }
    return null;
}
 
Example 13
Source File: IOSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testRuntime() throws Exception {
    KernelServices mainServices = startKernelServices(getSubsystemXml());
    XnioWorker worker = startXnioWorker(mainServices);
    Assert.assertEquals(ProcessorInfo.availableProcessors() * 2, worker.getIoThreadCount());
    Assert.assertEquals(ProcessorInfo.availableProcessors() * 16, worker.getOption(Options.WORKER_TASK_MAX_THREADS).intValue());
    PathAddress addr = PathAddress.parseCLIStyleAddress("/subsystem=io/worker=default");
    ModelNode op = Util.createOperation("read-resource", addr);
    op.get("include-runtime").set(true);
    mainServices.executeOperation(op);
}
 
Example 14
Source File: PoliciesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testDefaultPolicyWriteIgnored() throws Exception {
    KernelServices services = standardSubsystemTest("custom-policy.xml", true);
    ModelNode write = Util.getWriteAttributeOperation(getPolicyAddress("custom-b"), "default-policy", "test");
    ModelNode response = services.executeOperation(write);
    assertEquals(response.toString(), "success", response.get("outcome").asString());
    assertFalse(response.toString(), response.has(RESPONSE_HEADERS, OPERATION_REQUIRES_RELOAD));
    assertFalse(response.toString(), response.has(RESPONSE_HEADERS, OPERATION_REQUIRES_RESTART));
    checkNoDefaultPolicy(services, "custom-b");
}
 
Example 15
Source File: RemotingLegacySubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void updateAndCheckThreadAttribute(KernelServices services, String attrName, int before, int after) throws Exception {
    assertEquals(before, services.readWholeModel().get(SUBSYSTEM, RemotingExtension.SUBSYSTEM_NAME, attrName).asInt());
    ModelNode write = new ModelNode();
    write.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
    write.get(OP).set(WRITE_ATTRIBUTE_OPERATION);
    write.get(OP_ADDR).add(SUBSYSTEM, RemotingExtension.SUBSYSTEM_NAME);
    write.get(NAME).set(attrName);
    write.get(VALUE).set(after);
    ModelNode result = services.executeOperation(write);
    assertFalse(result.get(FAILURE_DESCRIPTION).toString(), result.hasDefined(FAILURE_DESCRIPTION));

    assertEquals(after, services.readWholeModel().get(SUBSYSTEM, RemotingExtension.SUBSYSTEM_NAME, attrName).asInt());
}
 
Example 16
Source File: IdentityOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testRemoveAttribute() throws Exception {
    KernelServices services = createKernelServicesBuilder(null)
            .setSubsystemXmlResource("identity-management.xml")
            .build();
    String principalName = "plainUser";
    PathAddress realmAddress = getSecurityRealmAddress("FileSystemRealm");
    ModelNode operation = createAddIdentityOperation(realmAddress, principalName);
    ModelNode result = services.executeOperation(operation);

    assertSuccessful(result);

    operation = createAddAttributeOperation(realmAddress, principalName, "firstName", "John");
    result = services.executeOperation(operation);
    assertSuccessful(result);

    operation = createAddAttributeOperation(realmAddress, principalName, "lastName", "Smith");
    result = services.executeOperation(operation);
    assertSuccessful(result);

    operation = createAddAttributeOperation(realmAddress, principalName, RoleDecoder.KEY_ROLES, "Admin", "Manager", "Employee");
    result = services.executeOperation(operation);
    assertSuccessful(result);

    operation = createReadIdentityOperation(realmAddress, principalName);
    result = services.executeOperation(operation);
    assertSuccessful(result);

    ModelNode resultNode = result.get(RESULT);
    ModelNode attributesNode = resultNode.get(ATTRIBUTES);

    assertTrue(attributesNode.isDefined());
    assertAttributeValue(attributesNode, "firstName", "John");
    assertAttributeValue(attributesNode, "lastName", "Smith");
    assertAttributeValue(attributesNode, RoleDecoder.KEY_ROLES, "Admin", "Manager", "Employee");

    operation = createRemoveAttributeOperation(realmAddress, principalName, "lastName");
    result = services.executeOperation(operation);
    assertSuccessful(result);

    operation = createRemoveAttributeOperation(realmAddress, principalName, RoleDecoder.KEY_ROLES, "Employee", "Manager");
    result = services.executeOperation(operation);
    assertSuccessful(result);

    operation = createReadIdentityOperation(realmAddress, principalName);
    result = services.executeOperation(operation);
    assertSuccessful(result);

    resultNode = result.get(RESULT);
    attributesNode = resultNode.get(ATTRIBUTES);

    assertTrue(attributesNode.isDefined());
    assertAttributeValue(attributesNode, "firstName", "John");
    assertFalse(attributesNode.get("lastName").isDefined());
    assertAttributeValue(attributesNode, RoleDecoder.KEY_ROLES, "Admin");
}
 
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 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 18
Source File: LoggingOperationsSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private ModelNode executeOperation(final KernelServices kernelServices, final ModelNode op, final boolean validateResult) {
    final ModelNode result = kernelServices.executeOperation(op);
    if (validateResult)
        assertTrue(SubsystemOperations.getFailureDescriptionAsString(result), SubsystemOperations.isSuccessfulOutcome(result));
    return result;
}
 
Example 19
Source File: AbstractOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void verifyRemoved(final KernelServices kernelServices, final ModelNode address) {
    final ModelNode op = SubsystemOperations.createReadResourceOperation(address);
    final ModelNode result = kernelServices.executeOperation(op);
    assertFalse("Resource not removed: " + address, SubsystemOperations.isSuccessfulOutcome(result));
}
 
Example 20
Source File: AbstractOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected ModelNode executeOperationForFailure(final KernelServices kernelServices, final ModelNode op) {
    final ModelNode result = kernelServices.executeOperation(op);
    assertFalse("Operation was expected to fail: " + op, SubsystemOperations.isSuccessfulOutcome(result));
    return result;
}