org.jboss.dmr.ModelType Java Examples

The following examples show how to use org.jboss.dmr.ModelType. 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: LsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testBasicPathArgumentRecognitionAndParsing() throws Exception {
    ModelNode request = ctx.buildRequest("ls / -l --resolve-expressions");
    ModelNode address = request.get("address");
    assertEquals(ModelType.LIST, address.getType());
    assertTrue(address.asList().isEmpty());
    assertTrue(request.hasDefined("steps"));
    final List<ModelNode> steps = request.get("steps").asList();
    assertEquals(3, steps.size());
    for(ModelNode step : steps) {
        address = step.get("address");
        assertTrue(address.asList().isEmpty());
    }

    request = ctx.buildRequest("ls /system-property");
    address = request.get("address");
    assertEquals(ModelType.LIST, address.getType());
    assertTrue(address.asList().isEmpty());
    assertFalse(request.hasDefined("steps"));
}
 
Example #2
Source File: ModuleLoadingResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void registerOperations(ManagementResourceRegistration resourceRegistration) {

    super.registerOperations(resourceRegistration);

    final OperationDefinition definition = new SimpleOperationDefinitionBuilder("list-resource-loader-paths", getResourceDescriptionResolver())
            .addParameter(MODULE_NAME)
            .setRuntimeOnly()
            .setReplyType(ModelType.LIST)
            .setReplyValueType(ModelType.STRING)
            .setDeprecated(ModelVersion.create(1, 4, 0))
            .setReadOnly()
            .build();

     resourceRegistration.registerOperationHandler(definition, new ModuleLocationHandler());
     resourceRegistration.registerOperationHandler(ModuleInfoHandler.DEFINITION, ModuleInfoHandler.INSTANCE);
}
 
Example #3
Source File: SecurityRealmAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Supplier<CallbackHandlerFactory> addSecretService(OperationContext context, ModelNode secret, String realmName, ServiceTarget serviceTarget,
                              ServiceBuilder<?> realmBuilder) throws OperationFailedException {
    final ServiceName secretServiceName = SecretIdentityService.ServiceUtil.createServiceName(realmName);
    final ModelNode resolvedValueNode = SecretServerIdentityResourceDefinition.VALUE.resolveModelAttribute(context, secret);
    boolean base64 = secret.get(SecretServerIdentityResourceDefinition.VALUE.getName()).getType() != ModelType.EXPRESSION;
    final ServiceBuilder<?> builder = serviceTarget.addService(secretServiceName);
    final Consumer<CallbackHandlerFactory> chfConsumer = builder.provides(secretServiceName);
    ExceptionSupplier<CredentialSource, Exception> credentialSourceSupplier = null;
    if (secret.hasDefined(CredentialReference.CREDENTIAL_REFERENCE)) {
        String keySuffix = SERVER_IDENTITY + KEY_DELIMITER + SECRET;
        credentialSourceSupplier = CredentialReference.getCredentialSourceSupplier(context, SecretServerIdentityResourceDefinition.CREDENTIAL_REFERENCE, secret, builder, keySuffix);
    }
    SecretIdentityService sis;
    if (secret.hasDefined(CredentialReference.CREDENTIAL_REFERENCE)) {
        sis = new SecretIdentityService(chfConsumer, credentialSourceSupplier, resolvedValueNode.asString(), false);
    } else {
        sis = new SecretIdentityService(chfConsumer, credentialSourceSupplier, resolvedValueNode.asString(), base64);
    }
    builder.setInstance(sis);
    builder.setInitialMode(ON_DEMAND);
    builder.install();

    return CallbackHandlerFactory.ServiceUtil.requires(realmBuilder, secretServiceName);
}
 
Example #4
Source File: OptionAttributeDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@SuppressWarnings("unchecked")
public OptionMap.Builder resolveOption(final ExpressionResolver context, final ModelNode model, OptionMap.Builder builder) throws OperationFailedException {
    ModelNode value = resolveModelAttribute(context, model);
    if (value.isDefined()) {
        if (getType() == ModelType.INT) {
            builder.set((Option<Integer>) option, value.asInt());
        } else if (getType() == ModelType.LONG) {
            builder.set(option, value.asLong());
        } else if (getType() == ModelType.BOOLEAN) {
            builder.set(option, value.asBoolean());
        } else if (optionType.isEnum()) {
            builder.set(option, option.parseValue(value.asString(), option.getClass().getClassLoader()));
        }else if (option.getClass().getSimpleName().equals("SequenceOption")) {
            builder.setSequence(option, value.asString().split("\\s*,\\s*"));
        } else if (getType() == ModelType.STRING) {
            builder.set(option, value.asString());
        } else {
            throw new OperationFailedException("Don't know how to handle: " + option + " with value: " + value);
        }
    }
    return builder;
}
 
Example #5
Source File: ValidateDescriptionProvidersTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testModelWithUndefinedElements() {
    ModelNode description = createSubsystemSkeleton(ModelType.LIST, ModelType.INT);
    description.get(NAMESPACE).set(new ModelNode());
    description.get(ATTRIBUTES, ROOT_ATTR, MIN);
    description.get(OPERATIONS, ROOT_OP, REQUEST_PROPERTIES, PARAM, MIN);
    description.get(CHILDREN, CHILD_TYPE, MIN_OCCURS);
    description.get(CHILDREN, CHILD_TYPE, MODEL_DESCRIPTION, CHILD_NAME, ATTRIBUTES, CHILD_ATTR, MIN);
    description.get(CHILDREN, CHILD_TYPE, MODEL_DESCRIPTION, CHILD_NAME, OPERATIONS, CHILD_OP, REQUEST_PROPERTIES, PARAM, MIN);
    description.get(CHILDREN, CHILD_TYPE, MODEL_DESCRIPTION, "EmptyChild");


    List<ValidationFailure> errors = validate(description, null);
    Assert.assertEquals(errors.toString(), 7, errors.size());
    assertFailure(errors.get(0), ROOT_ADDRESS);
    assertAttributeFailure(errors.get(1), ROOT_ADDRESS, ROOT_ATTR);
    assertOperationParameterFailure(errors.get(2), ROOT_ADDRESS, ROOT_OP, PARAM);
    assertFailure(errors.get(3), ROOT_ADDRESS);
    assertAttributeFailure(errors.get(4), CHILD_ADDRESS, CHILD_ATTR);
    assertOperationParameterFailure(errors.get(5), CHILD_ADDRESS, CHILD_OP, PARAM);
    assertFailure(errors.get(6), ROOT_ADDRESS.clone().add(CHILD_TYPE, "EmptyChild"));
}
 
Example #6
Source File: SocketBindingResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
static void validateInterfaceReference(final OperationContext context, final ModelNode binding) throws OperationFailedException {

        ModelNode interfaceNode = binding.get(INTERFACE.getName());
        if (interfaceNode.getType() == ModelType.STRING) { // ignore UNDEFINED and EXPRESSION
            String interfaceName = interfaceNode.asString();
            PathAddress operationAddress = context.getCurrentAddress();
            //This can be used on both the host and the server, the socket binding group will be a
            //sibling to the interface in the model
            PathAddress interfaceAddress = PathAddress.EMPTY_ADDRESS;
            for (PathElement element : operationAddress) {
                if (element.getKey().equals(ModelDescriptionConstants.SOCKET_BINDING_GROUP)) {
                    break;
                }
                interfaceAddress = interfaceAddress.append(element);
            }
            interfaceAddress = interfaceAddress.append(ModelDescriptionConstants.INTERFACE, interfaceName);
            try {
                context.readResourceFromRoot(interfaceAddress, false);
            } catch (RuntimeException e) {
                throw ControllerLogger.ROOT_LOGGER.nonexistentInterface(interfaceName, INTERFACE.getName());
            }
        }

    }
 
Example #7
Source File: TestUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static AttributeDefinition createAttribute(String name, ModelType type, String groupName, boolean runtimeOnly, boolean alias, boolean allowNull) {
    SimpleAttributeDefinitionBuilder attribute = SimpleAttributeDefinitionBuilder.create(name, type);
    if (runtimeOnly) {
        attribute.setStorageRuntime();
    }
    if(groupName != null && ! groupName.isEmpty()) {
        attribute.setAttributeGroup(groupName);
    }
    if(alias) {
        attribute.addFlag(AttributeAccess.Flag.ALIAS);
    }
    attribute.setAllowExpression(true);
    if (allowNull) {
        attribute.setRequired(false);
    }
    return attribute.build();
}
 
Example #8
Source File: ValidateOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testIntRangeTooLarge() throws Exception {
    getMainExtension().setAddAttributes(
            SimpleAttributeDefinitionBuilder.create("test", ModelType.INT)
                    .setValidator(new IntRangeValidator(Integer.MIN_VALUE, 10))
                    .build()
    );
    ModelNode operation = createAddOperation();
    operation.get("test").set(15);
    try {
        createKernelServicesBuilder(AdditionalInitialization.MANAGEMENT)
                .setBootOperations(operation)
                .build();
        Assert.fail("Not valid");
    } catch (Exception expected) {
        // ok
    }
}
 
Example #9
Source File: ParameterValueResolutionTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testList_NoBrackets() throws Exception {
    final CommandContext ctx = new MockCommandContext();
    ctx.setResolveParameterValues(true);
    final ModelNode value = parseList(ctx, "${cli.test.prop1},${cli.test.prop2},${cli.test.prop3}");
    assertNotNull(value);
    assertEquals(ModelType.LIST, value.getType());
    final List<ModelNode> list = value.asList();
    assertEquals(3, list.size());
    assertNotNull(list.get(0));
    assertEquals("one", list.get(0).asString());
    assertNotNull(list.get(1));
    assertEquals("two", list.get(1).asString());
    assertNotNull(list.get(2));
    assertEquals("three", list.get(2).asString());
}
 
Example #10
Source File: ManagementReadsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void validateServerLifecycleOps(ModelNode response, boolean isRunning) {
    ModelNode operations = response.get(RESULT, OPERATIONS);
    if (isRunning) {
        Assert.assertFalse(operations.toString(), operations.hasDefined(START));
        validateOperation(operations, RESTART, ModelType.STRING, BLOCKING, START_MODE);
        validateOperation(operations, RELOAD, ModelType.STRING, BLOCKING, START_MODE);
        validateOperation(operations, STOP, ModelType.STRING, BLOCKING, TIMEOUT, SUSPEND_TIMEOUT);
        validateOperation(operations, SUSPEND, null, TIMEOUT, SUSPEND_TIMEOUT);
        validateOperation(operations, RESUME, null);
        validateOperation(operations, DESTROY, null);
        validateOperation(operations, KILL, null);
    } else {
        validateOperation(operations, START, ModelType.STRING, BLOCKING, START_MODE);
        Assert.assertFalse(operations.toString(), operations.hasDefined(RESTART));
        Assert.assertFalse(operations.toString(), operations.hasDefined(RELOAD));
        Assert.assertFalse(operations.toString(), operations.hasDefined(STOP));
        Assert.assertFalse(operations.toString(), operations.hasDefined(SUSPEND));
        Assert.assertFalse(operations.toString(), operations.hasDefined(RESUME));
        Assert.assertFalse(operations.toString(), operations.hasDefined(DESTROY));
        Assert.assertFalse(operations.toString(), operations.hasDefined(KILL));
    }
}
 
Example #11
Source File: ExpressionTypeConverterUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testSimpleTypeExpressionList() throws Exception {
    ModelNode description = createDescription(ModelType.LIST, ModelType.INT);
    description.get(EXPRESSIONS_ALLOWED).set(true);
    TypeConverter converter = getConverter(description);
    assertCast(ArrayType.class, converter.getOpenType());

    ModelNode node = new ModelNode();
    node.add().set(new ValueExpression("${this.should.not.exist.!!!!!:1}"));
    node.add().set(new ValueExpression("${this.should.not.exist.!!!!!:2}"));

    String[] data = assertCast(String[].class, converter.fromModelNode(node));
    Assert.assertEquals("${this.should.not.exist.!!!!!:1}", data[0]);
    Assert.assertEquals("${this.should.not.exist.!!!!!:2}", data[1]);

    ModelNode newNode = converter.toModelNode(data);
    Assert.assertEquals(node, newNode);
}
 
Example #12
Source File: ModelTestModelDescriptionValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public String validate(ModelType currentType, ModelNode currentNode, String descriptor) {
    if (currentNode.hasDefined(descriptor)) {
        try {
            String value = currentNode.get(descriptor).asString();
            switch (value) {
                case JVM:
                case ALL_SERVICES:
                case RESOURCE_SERVICES:
                case NO_SERVICES:
                    return null;
                default:
                    return value + " is not a valid value for '" + descriptor + "'";
            }
        } catch (Exception e) {
            return "'" + descriptor + "' does not define a valid value";
        }
    }
    return null;
}
 
Example #13
Source File: ValidateDescriptionProvidersTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testIntMinMaxLength() {
    ModelNode description = createSubsystemSkeleton(ModelType.INT, (ModelType)null);
    description.get(ATTRIBUTES, ROOT_ATTR, MIN_LENGTH).set(5);
    description.get(ATTRIBUTES, ROOT_ATTR, MAX_LENGTH).set(5);
    description.get(CHILDREN, CHILD_TYPE, MODEL_DESCRIPTION, CHILD_NAME, OPERATIONS, CHILD_OP, REQUEST_PROPERTIES, PARAM, MIN_LENGTH).set(5);
    description.get(CHILDREN, CHILD_TYPE, MODEL_DESCRIPTION, CHILD_NAME, OPERATIONS, CHILD_OP, REQUEST_PROPERTIES, PARAM, MAX_LENGTH).set(5);
    description.get(CHILDREN, CHILD_TYPE, MODEL_DESCRIPTION, CHILD_NAME, OPERATIONS, CHILD_OP, REPLY_PROPERTIES, MAX_LENGTH).set(10);

    List<ValidationFailure> errors = validate(description, null);
    Assert.assertEquals(5, errors.size());

    assertAttributeFailure(errors.get(0), ROOT_ADDRESS, ROOT_ATTR);
    assertAttributeFailure(errors.get(1), ROOT_ADDRESS, ROOT_ATTR);
    assertOperationParameterFailure(errors.get(2), CHILD_ADDRESS, CHILD_OP, PARAM);
    assertOperationParameterFailure(errors.get(3), CHILD_ADDRESS, CHILD_OP, PARAM);
    assertOperationParameterFailure(errors.get(4), CHILD_ADDRESS, CHILD_OP, REPLY);
}
 
Example #14
Source File: WriteAttributeOperationTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testWriteReloadBytesAttributeExpressionOverValue() throws Exception {
    ModelNode operation = createOperation(READ_ATTRIBUTE_OPERATION, "profile", "profilType", "subsystem", "subsystem1");
    operation.get(NAME).set(BYTES_ATT_NAME);
    ModelNode result = executeForResult(operation);
    assertThat(result, is(notNullValue()));
    assertThat(result.getType(), is(ModelType.BYTES));
    assertThat(new String(result.asBytes(), UTF_8), is("wildfly"));

    ModelNode rewrite = createOperation(WRITE_ATTRIBUTE_OPERATION, "profile", "profilType", "subsystem", "subsystem1");
    rewrite.get(NAME).set(BYTES_ATT_NAME);
    rewrite.get(VALUE).set("${bytes-value}");
    result = executeCheckNoFailure(rewrite);
    assertThat(result, is(notNullValue()));
    assertThat(result.get(RESPONSE_HEADERS, OPERATION_REQUIRES_RELOAD).isDefined(), is(false));
    assertThat(result.get(RESPONSE_HEADERS, PROCESS_STATE).isDefined(), is(false));

    operation = createOperation(READ_ATTRIBUTE_OPERATION, "profile", "profilType", "subsystem", "subsystem1");
    operation.get(NAME).set(BYTES_ATT_NAME);
    result = executeForResult(operation);
    assertThat(result, is(notNullValue()));
    assertThat(result.getType(), is(ModelType.EXPRESSION));
    assertThat(result.asExpression().resolveString(), is("wildfly"));
}
 
Example #15
Source File: HelpSupport.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static String buildOperationArgumentType(ModelNode p) {
    StringBuilder builder = new StringBuilder();
    ModelType mt = getAdaptedArgumentType(p);
    boolean isList = mt == ModelType.LIST;
    builder.append(mt);
    boolean isObject = false;
    if (isList) {
        String t = null;
        if (p.hasDefined(Util.VALUE_TYPE)) {
            ModelNode vt = p.get(Util.VALUE_TYPE);
            isObject = isObject(vt);
        }
        if (isObject) {
            t = "OBJECT";
        } else {
            t = p.get(Util.VALUE_TYPE).asType().name();
        }
        builder.append(" of ").append(t);
    }
    return builder.toString();
}
 
Example #16
Source File: ArgumentValueParsingTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testObject() throws Exception {
    final ModelNode value = parse("a=b,c=d");
    assertNotNull(value);
    assertEquals(ModelType.OBJECT, value.getType());
    final List<Property> list = value.asPropertyList();
    assertEquals(2, list.size());
    Property prop = list.get(0);
    assertNotNull(prop);
    assertEquals("a", prop.getName());
    assertEquals("b", prop.getValue().asString());
    prop = list.get(1);
    assertNotNull(prop);
    assertEquals("c", prop.getName());
    assertEquals("d", prop.getValue().asString());
}
 
Example #17
Source File: ExpressionTypeConverterUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testSimpleTypeObject() throws Exception {
    ModelNode description = createDescription(ModelType.OBJECT, ModelType.LONG);
    TypeConverter converter = getConverter(description);

    assertMapType(assertCast(TabularType.class, converter.getOpenType()), SimpleType.STRING, SimpleType.STRING);

    ModelNode node = new ModelNode();
    node.get("one").set(1L);
    node.get("two").set(2L);

    TabularData tabularData = assertCast(TabularData.class, converter.fromModelNode(node));
    Assert.assertEquals(2, tabularData.size());
    Assert.assertEquals("1", tabularData.get(new Object[] {"one"}).get("value"));
    Assert.assertEquals("2", tabularData.get(new Object[] {"two"}).get("value"));

    Assert.assertEquals(node, converter.toModelNode(tabularData));

    //Allow plain map as well? Yeah why not!
    Map<String, String> map = new HashMap<String, String>();
    map.put("one", "1");
    map.put("two", "2");
    Assert.assertEquals(node, converter.toModelNode(map));
}
 
Example #18
Source File: LogLevelValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private LogLevelValidator(final boolean nullable, final boolean allowExpressions, final Level... levels) {
    super(ModelType.STRING, nullable, allowExpressions);
    allowedValues = Arrays.asList(levels);
    allowedValues.sort(LevelComparator.INSTANCE);
    nodeValues = new ArrayList<>(allowedValues.size());
    for (Level level : allowedValues) {
        nodeValues.add(new ModelNode(level.getName()));
    }
}
 
Example #19
Source File: MaskedAddressValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void validateParameter(String parameterName, ModelNode value) throws OperationFailedException {
    super.validateParameter(parameterName, value);
    if (value.isDefined() && value.getType() != ModelType.EXPRESSION) {
        parseMasked(value);
    }
}
 
Example #20
Source File: ExpressionTypeConverterUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testBigIntegerEmptyConverter() {
    ModelNode description = createDescription(ModelType.BIG_INTEGER);
    TypeConverter converter = getConverter(description);
    Assert.assertEquals(SimpleType.STRING, converter.getOpenType());
    Assert.assertNull(converter.fromModelNode(new ModelNode().set("")));
}
 
Example #21
Source File: AdminOnlyPolicyTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void validateProfiles(String... expectedNames) throws IOException {
    Set<String> set = new HashSet<String>(Arrays.asList(expectedNames));
    ModelNode op = Util.createEmptyOperation(ModelDescriptionConstants.READ_CHILDREN_NAMES_OPERATION, PathAddress.EMPTY_ADDRESS);
    op.get(ModelDescriptionConstants.CHILD_TYPE).set(ModelDescriptionConstants.PROFILE);
    ModelNode result = executeForResult(domainSlaveLifecycleUtil.getDomainClient(), op);
    Assert.assertEquals(result.toString(), ModelType.LIST, result.getType());
    Assert.assertEquals(result.toString(), set.size(), result.asInt());
    for (ModelNode profile : result.asList()) {
        String name = profile.asString();
        Assert.assertTrue(name, set.remove(name));
    }
    Assert.assertTrue(set.toString(), set.isEmpty());
}
 
Example #22
Source File: ValidateDescriptionProvidersTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testConfiguredAllowNullValueTypeForObjectParameter() {
    ModelNode description = createSubsystemSkeleton(ModelType.OBJECT, (ModelType)null);

    ValidationConfiguration arbitraryDescriptors = new ValidationConfiguration();
    arbitraryDescriptors.allowNullValueTypeForAttribute(ROOT_ADDRESS, ROOT_ATTR);
    arbitraryDescriptors.allowNullValueTypeForOperationParameter(ROOT_ADDRESS, ROOT_OP, PARAM);
    arbitraryDescriptors.allowNullValueTypeForAttribute(CHILD_ADDRESS, CHILD_ATTR);
    arbitraryDescriptors.allowNullValueTypeForOperationParameter(CHILD_ADDRESS, CHILD_OP, PARAM);

    List<ValidationFailure> errors = validate(description, arbitraryDescriptors);
    Assert.assertEquals(2, errors.size());
    assertOperationParameterFailure(errors.get(0), ROOT_ADDRESS, ROOT_OP, REPLY_PROPERTIES);
    assertOperationParameterFailure(errors.get(1), CHILD_ADDRESS, CHILD_OP, REPLY_PROPERTIES);
}
 
Example #23
Source File: ExpressionTypeConverterUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testIntEmptyConverter() {
    ModelNode description = createDescription(ModelType.INT);
    TypeConverter converter = getConverter(description);
    Assert.assertEquals(SimpleType.STRING, converter.getOpenType());
    Assert.assertNull(converter.fromModelNode(new ModelNode().set("")));
}
 
Example #24
Source File: ExpressionTypeConverterUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testBooleanExpressionConverter() throws Exception {
    ModelNode description = createDescription(ModelType.BOOLEAN);
    TypeConverter converter = getConverter(description);
    String data = assertCast(String.class, converter.fromModelNode(new ModelNode().set(new ValueExpression("${this.should.not.exist.!!!!!:false}"))));
    Assert.assertEquals("${this.should.not.exist.!!!!!:false}", data);
    ModelNode newNode = converter.toModelNode("${this.should.not.exist.!!!!!:true}");
    Assert.assertEquals(ModelType.EXPRESSION, newNode.getType());
    Assert.assertEquals("${this.should.not.exist.!!!!!:true}", newNode.asString());
    assertToArray(converter, "true", "${this.should.not.exist.!!!!!:false}");
}
 
Example #25
Source File: ServerConfigResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void registerServerLifecycleOperations(final ManagementResourceRegistration resourceRegistration, final ServerInventory serverInventory) {
    // Lifecycle ops are deprecated on the server-config resource but not on server
    boolean serverConfig = resourceRegistration.getPathAddress().getLastElement().getKey().equals(SERVER_CONFIG);
    // Mark the lifecycle ops on the server-config resources as deprecated.
    // Some already were deprecated in version 7, so use a different deprecated version for those
    ModelVersion deprecatedVersion = serverConfig ? ModelVersion.create(9) : null;
    ModelVersion existingDeprecatedVersion = serverConfig ? ModelVersion.create(7) : null;

    resourceRegistration.registerOperationHandler(
            getDomainServerLifecycleDefinition(START, ModelType.STRING, deprecatedVersion, BLOCKING, START_MODE),
            new ServerStartHandler(serverInventory));
    resourceRegistration.registerOperationHandler(
            getDomainServerLifecycleDefinition(RESTART, ModelType.STRING, deprecatedVersion, BLOCKING, START_MODE),
            new ServerRestartHandler(serverInventory));
    resourceRegistration.registerOperationHandler(
            getDomainServerLifecycleDefinition(STOP, ModelType.STRING, deprecatedVersion, BLOCKING, TIMEOUT, SUSPEND_TIMEOUT),
            new ServerStopHandler(serverInventory));
    resourceRegistration.registerOperationHandler(
            getDomainServerLifecycleDefinition(RELOAD, ModelType.STRING, existingDeprecatedVersion, BLOCKING, START_MODE),
            new ServerReloadHandler(serverInventory));
    resourceRegistration.registerOperationHandler(
            getDomainServerLifecycleDefinition(SUSPEND, null, existingDeprecatedVersion, TIMEOUT, SUSPEND_TIMEOUT),
            new ServerSuspendHandler(serverInventory));
    resourceRegistration.registerOperationHandler(
            getDomainServerLifecycleDefinition(RESUME, null, existingDeprecatedVersion),
            new ServerResumeHandler(serverInventory));
    resourceRegistration.registerOperationHandler(
            getDomainServerLifecycleDefinition(DESTROY, null, deprecatedVersion),
            new ServerProcessHandlers.ServerDestroyHandler(serverInventory));
    resourceRegistration.registerOperationHandler(
            getDomainServerLifecycleDefinition(KILL, null, deprecatedVersion),
            new ServerProcessHandlers.ServerKillHandler(serverInventory));
}
 
Example #26
Source File: LegacyTypeConverterUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testBytesConverter() {
    ModelNode description = createDescription(ModelType.BYTES);
    TypeConverter converter = getConverter(description);
    Assert.assertEquals(ArrayType.getPrimitiveArrayType(byte[].class), converter.getOpenType());
    Assert.assertTrue(Arrays.equals(new byte[] {1,2,3}, assertCast(byte[].class, converter.fromModelNode(new ModelNode().set(new byte[] {1,2,3})))));
    Assert.assertTrue(Arrays.equals(new byte[] {1,2,3}, converter.toModelNode(new byte[] {1,2,3}).asBytes()));
    byte[][] bytes = assertCast(byte[][].class, converter.toArray(createList(new byte[] {1,2,3}, new byte[] {4,5,6})));
    Assert.assertEquals(2, bytes.length);
    Assert.assertTrue(Arrays.equals(new byte[] {1,2,3}, bytes[0]));
    Assert.assertTrue(Arrays.equals(new byte[] {4,5,6}, bytes[1]));
}
 
Example #27
Source File: CertificateAuthoritiesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testAddCertificateAuthorityWithEmptyStagingUrl() {
    addCertificateAuthorityWithoutStagingUrl();
    try {
        ModelNode operation = new ModelNode();
        operation.get(ClientConstants.OP_ADDR).add("subsystem", "elytron").add("certificate-authority", CERTIFICATE_AUTHORITY_NAME);
        operation.get(ClientConstants.OP).set(ClientConstants.READ_RESOURCE_OPERATION);
        ModelNode result = assertSuccess(services.executeOperation(operation)).get(ClientConstants.RESULT);
        assertEquals(SIMULATED_LETS_ENCRYPT_ENDPOINT, result.get(ElytronDescriptionConstants.URL).asString());
        assertEquals(ModelType.UNDEFINED, result.get(ElytronDescriptionConstants.STAGING_URL).getType());
    } finally {
        removeCertificateAuthority();
    }
}
 
Example #28
Source File: ReadResourceDescriptionAccessControlTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ModelNode getWildcardResourceRegistrationResult(ModelNode result) {
    Assert.assertEquals(ModelType.LIST, result.getType());
    List<ModelNode> list = result.asList();
    Assert.assertEquals(1, list.size());
    ModelNode realResult = list.get(0);
    return realResult.get(RESULT);
}
 
Example #29
Source File: GenericTypeOperationHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected ModelType asType(ModelNode type) {
    if(type == null) {
        return null;
    }
    try {
        return type.asType();
    } catch(IllegalArgumentException e) {
        // the value type is a structure
        return null;
    }
}
 
Example #30
Source File: ValidateDescriptionProvidersTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testConfiguredAllowNullValueTypeForObjectReplyProperties() {
    ModelNode description = createSubsystemSkeleton(ModelType.OBJECT, (ModelType)null);

    ValidationConfiguration arbitraryDescriptors = new ValidationConfiguration();
    arbitraryDescriptors.allowNullValueTypeForAttribute(ROOT_ADDRESS, ROOT_ATTR);
    arbitraryDescriptors.allowNullValueTypeForOperationReplyProperties(ROOT_ADDRESS, ROOT_OP);
    arbitraryDescriptors.allowNullValueTypeForAttribute(CHILD_ADDRESS, CHILD_ATTR);
    arbitraryDescriptors.allowNullValueTypeForOperationReplyProperties(CHILD_ADDRESS, CHILD_OP);

    List<ValidationFailure> errors = validate(description, arbitraryDescriptors);
    Assert.assertEquals(2, errors.size());
    assertOperationParameterFailure(errors.get(0), ROOT_ADDRESS, ROOT_OP, PARAM);
    assertOperationParameterFailure(errors.get(1), CHILD_ADDRESS, CHILD_OP, PARAM);
}