Skip to content

Commit

Permalink
[WFLY-7506] Temporary test utils, and needed changes for ejb3
Browse files Browse the repository at this point in the history
transformers tests to pass once WFCORE-1892 has been merged and
released.
  • Loading branch information
kabir committed Nov 8, 2016
1 parent 8aef4f8 commit bb8399c
Show file tree
Hide file tree
Showing 3 changed files with 1,511 additions and 17 deletions.
Expand Up @@ -2,9 +2,12 @@


import static org.jboss.as.controller.capability.RuntimeCapability.buildDynamicCapabilityName; import static org.jboss.as.controller.capability.RuntimeCapability.buildDynamicCapabilityName;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.CHILD_TYPE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_CHILDREN_NAMES_OPERATION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_RESOURCE_OPERATION; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_RESOURCE_OPERATION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT;
import static org.jboss.as.ejb3.subsystem.IdentityResourceDefinition.IDENTITY_CAPABILITY; import static org.jboss.as.ejb3.subsystem.IdentityResourceDefinition.IDENTITY_CAPABILITY;


import java.io.IOException; import java.io.IOException;
Expand All @@ -17,9 +20,9 @@
import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement; import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.operations.common.Util; import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.model.test.FailedOperationTransformationConfig; import org.jboss.as.ejb3.subsystem.temp.FailedOperationTransformationConfig;
import org.jboss.as.ejb3.subsystem.temp.ModelTestUtils;
import org.jboss.as.model.test.ModelTestControllerVersion; import org.jboss.as.model.test.ModelTestControllerVersion;
import org.jboss.as.model.test.ModelTestUtils;
import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest; import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest;
import org.jboss.as.subsystem.test.AdditionalInitialization; import org.jboss.as.subsystem.test.AdditionalInitialization;
import org.jboss.as.subsystem.test.KernelServices; import org.jboss.as.subsystem.test.KernelServices;
Expand Down Expand Up @@ -173,23 +176,28 @@ private static FailedOperationTransformationConfig createFailedOperationTransfor


if (EJB3Model.VERSION_1_2_1.matches(version)) { if (EJB3Model.VERSION_1_2_1.matches(version)) {



// create a chained config to apply multiple transformation configs to each one of a collection of attributes // create a chained config to apply multiple transformation configs to each one of a collection of attributes
FailedOperationTransformationConfig.ChainedConfig chainedConfig = FailedOperationTransformationConfig.ChainedConfig.createBuilder( FailedOperationTransformationConfig.ChainedConfig chainedSubsystemConfig = FailedOperationTransformationConfig.ChainedConfig.createBuilder(
/*EJB3SubsystemRootResourceDefinition.DEFAULT_SFSB_PASSIVATION_DISABLED_CACHE,*/ EJB3SubsystemRootResourceDefinition.DISABLE_DEFAULT_EJB_PERMISSIONS) /*EJB3SubsystemRootResourceDefinition.DEFAULT_SFSB_PASSIVATION_DISABLED_CACHE,*/ EJB3SubsystemRootResourceDefinition.DISABLE_DEFAULT_EJB_PERMISSIONS)
.addConfig(new FailedOperationTransformationConfig.NewAttributesConfig( .addConfig(new FailedOperationTransformationConfig.NewAttributesConfig(
/*EJB3SubsystemRootResourceDefinition.DEFAULT_SFSB_PASSIVATION_DISABLED_CACHE,*/ EJB3SubsystemRootResourceDefinition.LOG_EJB_EXCEPTIONS, EJB3SubsystemRootResourceDefinition.ALLOW_EJB_NAME_REGEX)) /*EJB3SubsystemRootResourceDefinition.DEFAULT_SFSB_PASSIVATION_DISABLED_CACHE,*/ EJB3SubsystemRootResourceDefinition.LOG_EJB_EXCEPTIONS, EJB3SubsystemRootResourceDefinition.ALLOW_EJB_NAME_REGEX))
.addConfig(new CorrectFalseToTrue(EJB3SubsystemRootResourceDefinition.DISABLE_DEFAULT_EJB_PERMISSIONS)) .addConfig(new CorrectFalseToTrue(EJB3SubsystemRootResourceDefinition.DISABLE_DEFAULT_EJB_PERMISSIONS))
.build(); .build();


// discard new attributes default-sfsb-passivation-disabled-cache, disable-default-ejb-permissions // discard new attributes default-sfsb-passivation-disabled-cache, disable-default-ejb-permissions
config.addFailedAttribute(subsystemAddress, chainedConfig); config.addFailedAttribute(subsystemAddress, chainedSubsystemConfig);


// make sure that we have a file-data-store matching the custom-data-store attribute value // make sure that we have a file-data-store matching the custom-data-store attribute value
final PathAddress timerServiceAddr = subsystemAddress.append(EJB3SubsystemModel.TIMER_SERVICE_PATH); final PathAddress timerServiceAddr = subsystemAddress.append(EJB3SubsystemModel.TIMER_SERVICE_PATH);
final PathAddress badFileStoreAddr = timerServiceAddr.append(PathElement.pathElement(EJB3SubsystemModel.FILE_DATA_STORE, "file-data-store-rename-to-default")); final PathAddress badFileStoreAddr = timerServiceAddr.append(PathElement.pathElement(EJB3SubsystemModel.FILE_DATA_STORE, "file-data-store-rename-to-default"));
final PathAddress newFileStoreAddr = timerServiceAddr.append(PathElement.pathElement(EJB3SubsystemModel.FILE_DATA_STORE, "file-data-store")); final PathAddress newFileStoreAddr = timerServiceAddr.append(PathElement.pathElement(EJB3SubsystemModel.FILE_DATA_STORE, "file-data-store"));
config.addFailedAttribute(badFileStoreAddr, new ChangeAddressConfig(services, badFileStoreAddr, newFileStoreAddr)); config.addFailedAttribute(badFileStoreAddr, new ChangeAddressConfig(services, badFileStoreAddr, newFileStoreAddr));


//Add a config to remove the extra file-data-store. This is against the fixed address from ChangeAddressConfig
RemoveExtraFileStoreConfig removeExtraFileStoreConfig = new RemoveExtraFileStoreConfig(services, timerServiceAddr);
config.addFailedAttribute(newFileStoreAddr, removeExtraFileStoreConfig);

// reject the resource /subsystem=ejb3/service=timer-service/file-data-store=file-data-store-rejected since we already have a file-data-store // reject the resource /subsystem=ejb3/service=timer-service/file-data-store=file-data-store-rejected since we already have a file-data-store
config.addFailedAttribute(subsystemAddress.append(EJB3SubsystemModel.TIMER_SERVICE_PATH, PathElement.pathElement(EJB3SubsystemModel.FILE_DATA_STORE, "file-data-store-rejected")), config.addFailedAttribute(subsystemAddress.append(EJB3SubsystemModel.TIMER_SERVICE_PATH, PathElement.pathElement(EJB3SubsystemModel.FILE_DATA_STORE, "file-data-store-rejected")),
FailedOperationTransformationConfig.REJECTED_RESOURCE); FailedOperationTransformationConfig.REJECTED_RESOURCE);
Expand Down Expand Up @@ -218,6 +226,13 @@ private static FailedOperationTransformationConfig createFailedOperationTransfor
// reject the resource /subsystem=ejb3/service=identity // reject the resource /subsystem=ejb3/service=identity
config.addFailedAttribute(subsystemAddress.append(EJB3SubsystemModel.IDENTITY_PATH), FailedOperationTransformationConfig.REJECTED_RESOURCE); config.addFailedAttribute(subsystemAddress.append(EJB3SubsystemModel.IDENTITY_PATH), FailedOperationTransformationConfig.REJECTED_RESOURCE);



//Special handling for this test!!!!
//Don't transform the resulting composite, instead rather transform the individual steps
config.setDontTransformComposite();

//Remove the extra file-data-store entries so that our transformers can work
config.setCallback(() -> removeExtraFileStoreConfig.removeExtraFileDataStore());
} }


if (EJB3Model.VERSION_1_3_0.matches(version)) { if (EJB3Model.VERSION_1_3_0.matches(version)) {
Expand Down Expand Up @@ -285,7 +300,31 @@ protected ModelNode correctValue(ModelNode toResolve, boolean isWriteAttribute)


} }


private static class ChangeAddressConfig implements FailedOperationTransformationConfig.PathAddressConfig { private abstract static class BasePathAddressConfig implements FailedOperationTransformationConfig.PathAddressConfig {

@Override
public boolean expectDiscarded(ModelNode operation) {
//The reject simply forwards on the original operation to make it fail
return false;
}

@Override
public List<ModelNode> createWriteAttributeOperations(ModelNode operation) {
return Collections.emptyList();
}

@Override
public boolean expectFailedWriteAttributeOperation(ModelNode operation) {
throw new IllegalStateException("Should not get called");
}

@Override
public ModelNode correctWriteAttributeOperation(ModelNode operation) {
throw new IllegalStateException("Should not get called");
}
}

private static class ChangeAddressConfig extends BasePathAddressConfig {
KernelServices services; KernelServices services;
private final PathAddress badAddress; private final PathAddress badAddress;
private final PathAddress newAddress; private final PathAddress newAddress;
Expand Down Expand Up @@ -327,29 +366,70 @@ public ModelNode correctOperation(ModelNode operation) {
return op; return op;
} }


@Override private boolean isBadAddress(ModelNode operation) {
public boolean expectDiscarded(ModelNode operation) { return PathAddress.pathAddress(operation.require(OP_ADDR)).equals(badAddress);
//The reject simply forwards on the original operation to make it fail }
return false; }

private static class RemoveExtraFileStoreConfig extends BasePathAddressConfig {
private final KernelServices kernelServices;
private final PathAddress timerServiceAddress;
private final PathAddress rejectedFileDataStoreAddress;
private ModelNode removedResourceModel;

public RemoveExtraFileStoreConfig(KernelServices kernelServices, PathAddress timerServiceAddress) {
this.kernelServices = kernelServices;
this.timerServiceAddress = timerServiceAddress;
rejectedFileDataStoreAddress = timerServiceAddress.append(EJB3SubsystemModel.FILE_DATA_STORE_PATH.getKey(), "file-data-store-rejected");
} }


@Override @Override
public List<ModelNode> createWriteAttributeOperations(ModelNode operation) { public boolean expectFailed(ModelNode operation) {
return Collections.emptyList(); return hasTooManyFileStores();
} }


@Override @Override
public boolean expectFailedWriteAttributeOperation(ModelNode operation) { public boolean canCorrectMore(ModelNode operation) {
throw new IllegalStateException("Should not get called"); return hasTooManyFileStores();
}

private boolean hasTooManyFileStores() {
ModelNode op = Util.createOperation(READ_CHILDREN_NAMES_OPERATION, timerServiceAddress);
op.get(CHILD_TYPE).set(EJB3SubsystemModel.FILE_DATA_STORE_PATH.getKey());
ModelNode result = ModelTestUtils.checkOutcome(kernelServices.executeOperation(op)).get(RESULT);
List<ModelNode> list = result.asList();
return list.size() > 1;
} }


@Override @Override
public ModelNode correctWriteAttributeOperation(ModelNode operation) { public ModelNode correctOperation(ModelNode operation) {
throw new IllegalStateException("Should not get called"); //Here we don't actually correct the operation, but we remove the extra file-data-store which causes the
//rejection


ModelNode rr = Util.createEmptyOperation(READ_RESOURCE_OPERATION, rejectedFileDataStoreAddress);
removedResourceModel = ModelTestUtils.checkOutcome(kernelServices.executeOperation(rr)).get(RESULT);

removeExtraFileDataStore();
return operation;
} }


private boolean isBadAddress(ModelNode operation) { void removeExtraFileDataStore() {
return PathAddress.pathAddress(operation.require(OP_ADDR)).equals(badAddress); ModelNode remove = Util.createRemoveOperation(rejectedFileDataStoreAddress);
ModelTestUtils.checkOutcome(kernelServices.executeOperation(remove));
}

@Override
public void operationDone(ModelNode operation) {
if (removedResourceModel != null) {
//Re-add the removed resource, since we have more checks in the config for file-data-store=file-data-store-rejected
ModelNode add = Util.createAddOperation(
timerServiceAddress.append(EJB3SubsystemModel.FILE_DATA_STORE_PATH.getKey(), "file-data-store-rejected"));
for (String key : removedResourceModel.keys()) {
add.get(key).set(removedResourceModel.get(key));
}
ModelNode result = ModelTestUtils.checkOutcome(kernelServices.executeOperation(add)).get(RESULT);
}
} }
} }
} }

0 comments on commit bb8399c

Please sign in to comment.