Skip to content

Commit

Permalink
Generalize mod_cluster subsystem schema
Browse files Browse the repository at this point in the history
  • Loading branch information
rhusar committed Nov 1, 2016
1 parent e3cf127 commit cd0fd3b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ public void initialize(ExtensionContext context) {

@Override
public void initializeParsers(ExtensionParsingContext context) {
for (Namespace namespace : Namespace.values()) {
XMLElementReader<List<ModelNode>> reader = namespace.getXMLReader();
for (ModClusterSchema schema : ModClusterSchema.values()) {
XMLElementReader<List<ModelNode>> reader = schema.getXMLReader();
if (reader != null) {
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, namespace.getUri(), namespace.getXMLReader());
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, schema.getNamespaceUri(), schema.getXMLReader());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
package org.wildfly.extension.mod_cluster;

import org.jboss.as.clustering.controller.Schema;
import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.XMLElementReader;

Expand All @@ -30,37 +31,39 @@
/**
* @author Jean-Frederic Clere
* @author Paul Ferraro
* @author Radoslav Husar
*/
public enum Namespace {
// must be first
UNKNOWN(0, 0, null),
public enum ModClusterSchema implements Schema<ModClusterSchema> {

MODCLUSTER_1_0(1, 0, new ModClusterSubsystemXMLReader_1_0()),
MODCLUSTER_1_1(1, 1, new ModClusterSubsystemXMLReader_1_1()),
MODCLUSTER_1_2(1, 2, new ModClusterSubsystemXMLReader_1_2()),
MODCLUSTER_2_0(2, 0, new ModClusterSubsystemXMLReader_2_0()),
;
/**
* The current namespace version.
*/
public static final Namespace CURRENT = MODCLUSTER_2_0;
public static final ModClusterSchema CURRENT = MODCLUSTER_2_0;

private final int major;
private final int minor;
private final XMLElementReader<List<ModelNode>> reader;

Namespace(int major, int minor, XMLElementReader<List<ModelNode>> reader) {
ModClusterSchema(int major, int minor, XMLElementReader<List<ModelNode>> reader) {
this.major = major;
this.minor = minor;
this.reader = reader;
}

/**
* Get the URI of this namespace.
*
* @return the URI
*/
public String getUri() {
@Override
public int major() {
return this.major;
}

@Override
public int minor() {
return this.minor;
}

@Override
public String getNamespaceUri() {
return String.format(Locale.ROOT, "urn:jboss:domain:%s:%d.%d", ModClusterExtension.SUBSYSTEM_NAME, this.major, this.minor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class ModClusterSubsystemXMLWriter implements XMLElementWriter<SubsystemM
@Override
public void writeContent(final XMLExtendedStreamWriter writer, final SubsystemMarshallingContext context)
throws XMLStreamException {
context.startSubsystemElement(Namespace.CURRENT.getUri(), false);
context.startSubsystemElement(ModClusterSchema.CURRENT.getNamespaceUri(), false);

ModelNode node = context.getModelNode();
if (node.get(ModClusterConfigResourceDefinition.PATH.getKeyValuePair()).isDefined()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
import static org.wildfly.extension.mod_cluster.CommonAttributes.CONFIGURATION;
import static org.wildfly.extension.mod_cluster.CommonAttributes.MOD_CLUSTER_CONFIG;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest;
import org.jboss.as.clustering.subsystem.ClusteringSubsystemTest;
import org.jboss.as.subsystem.test.AdditionalInitialization;
import org.jboss.as.subsystem.test.KernelServices;
import org.jboss.as.subsystem.test.KernelServicesBuilder;
Expand All @@ -38,60 +40,64 @@
import org.jboss.msc.service.ServiceController;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

/**
* @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
* @author Jean-Frederic Clere
* @author Radoslav Husar
* @version Apr 2015
*/
public class ModClusterSubsystemParsingTestCase extends AbstractSubsystemBaseTest {
@RunWith(Parameterized.class)
public class ModClusterSubsystemParsingTestCase extends ClusteringSubsystemTest {

public ModClusterSubsystemParsingTestCase() {
super(ModClusterExtension.SUBSYSTEM_NAME, new ModClusterExtension());
}

// --------------------------------------------------- Standard Subsystem tests
private final ModClusterSchema schema;
private final int expectedOperationCount;

@Test
public void testXsd10() throws Exception {
standardSubsystemTest("subsystem_1_0.xml", false);
public ModClusterSubsystemParsingTestCase(ModClusterSchema schema, int expectedOperationCount) {
super(ModClusterExtension.SUBSYSTEM_NAME, new ModClusterExtension(), String.format("subsystem_%d_%d.xml", schema.major(), schema.minor()));
this.schema = schema;
this.expectedOperationCount = expectedOperationCount;
}

@Test
public void testXsd11() throws Exception {
standardSubsystemTest("subsystem_1_1.xml", false);
}
@Parameterized.Parameters
public static Collection<Object[]> data() {
Object[][] data = new Object[][] {
{ ModClusterSchema.MODCLUSTER_1_0, 13 },
{ ModClusterSchema.MODCLUSTER_1_1, 13 },
{ ModClusterSchema.MODCLUSTER_1_2, 15 },
{ ModClusterSchema.MODCLUSTER_2_0, 15 },

@Test
public void testXsd12() throws Exception {
standardSubsystemTest("subsystem_1_2.xml", false);
};
return Arrays.asList(data);
}

/**
* Tests that the xml is parsed into the correct operations.
*/
@Test
public void testSubsystemWithSimpleLoadProvider() throws Exception {
super.standardSubsystemTest("subsystem_2_0_simple-load-provider.xml");
}
public void testParseSubsystem() throws Exception {
List<ModelNode> operations = this.parse(this.getSubsystemXml());

@Override
protected String getSubsystemXml() throws IOException {
return readResource("subsystem_2_0.xml");
Assert.assertEquals(this.expectedOperationCount, operations.size());
}

@Override
protected String getSubsystemXsdPath() throws Exception {
return "schema/jboss-as-mod-cluster_2_0.xsd";
return String.format("schema/jboss-as-mod-cluster_%d_%d.xsd", schema.major(), schema.minor());
}

@Override
protected String[] getSubsystemTemplatePaths() throws IOException {
return new String[] {
"/subsystem-templates/mod_cluster.xml"
};
@Test
public void testSubsystemWithSimpleLoadProvider() throws Exception {
if (schema != ModClusterSchema.CURRENT) return;

super.standardSubsystemTest("subsystem_2_0_simple-load-provider.xml");
}

@Test
public void testSSL() throws Exception {
if (schema != ModClusterSchema.CURRENT) return;

KernelServicesBuilder builder = createKernelServicesBuilder(new AdditionalInitialization()).setSubsystemXml(getSubsystemXml());
KernelServices services = builder.build();
ModelNode model = services.readWholeModel();
Expand Down

0 comments on commit cd0fd3b

Please sign in to comment.