Skip to content

Commit

Permalink
Tests for resource caching
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Feb 23, 2018
1 parent ba8be76 commit 6be4a2f
Show file tree
Hide file tree
Showing 10 changed files with 964 additions and 197 deletions.
Expand Up @@ -115,6 +115,9 @@ public abstract class AbstractDirectManualResourceTest extends AbstractManualRes

protected static final File RESOURCE_MANUAL_FILE = new File(TEST_DIR, "resource-manual.xml");
protected static final String RESOURCE_MANUAL_OID = "0ef80ab8-2906-11e7-b81a-3f343e28c264";

protected static final File RESOURCE_MANUAL_CAPABILITIES_FILE = new File(TEST_DIR, "resource-manual-capabilities.xml");
protected static final String RESOURCE_MANUAL_CAPABILITIES_OID = "0ef80ab8-2906-11e7-b81a-3f343e28c264";

protected static final File RESOURCE_SEMI_MANUAL_FILE = new File(TEST_DIR, "resource-semi-manual.xml");
protected static final String RESOURCE_SEMI_MANUAL_OID = "aea5a57c-2904-11e7-8020-7b121a9e3595";
Expand Down
Expand Up @@ -77,6 +77,7 @@
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.api_types_3.ImportOptionsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentPolicyEnforcementType;
Expand Down Expand Up @@ -289,8 +290,12 @@ public void test000Sanity() throws Exception {
}

@Test
public void test003Connection() throws Exception {
final String TEST_NAME = "test003Connection";
public void test012TestConnection() throws Exception {
final String TEST_NAME = "test012TestConnection";
testConnection(TEST_NAME);
}

public void testConnection(final String TEST_NAME) throws Exception {
displayTestTitle(TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
Expand All @@ -303,15 +308,22 @@ public void test003Connection() throws Exception {
Element resourceXsdSchemaElementBefore = ResourceTypeUtil.getResourceXsdSchema(resourceBefore);
assertResourceSchemaBeforeTest(resourceXsdSchemaElementBefore);

CapabilitiesType capabilities = resourceBefore.getCapabilities();
if (capabilities != null) {
AssertJUnit.assertNull("Native capabilities present before test connection. Bad test setup?", capabilities.getNative());
CapabilitiesType capabilitiesBefore = resourceBefore.getCapabilities();
if (nativeCapabilitiesEntered()) {
AssertJUnit.assertNotNull("Native capabilities missing before test connection. Bad test setup?", capabilitiesBefore);
AssertJUnit.assertNotNull("Native capabilities missing before test connection. Bad test setup?", capabilitiesBefore.getNative());
} else {
if (capabilitiesBefore != null) {
AssertJUnit.assertNull("Native capabilities present before test connection. Bad test setup?", capabilitiesBefore.getNative());
}
}

// WHEN
displayWhen(TEST_NAME);
OperationResult testResult = modelService.testResource(getResourceOid(), task);

// THEN
displayThen(TEST_NAME);
display("Test result", testResult);
TestUtil.assertSuccess("Test resource failed (result)", testResult);

Expand All @@ -325,30 +337,46 @@ public void test003Connection() throws Exception {
assertNotNull("No schema after test connection", resourceXsdSchemaElementAfter);

String resourceXml = prismContext.serializeObjectToString(resourceRepoAfter, PrismContext.LANG_XML);
display("Resource XML", resourceXml);
display("Resource XML after test connection", resourceXml);

CachingMetadataType cachingMetadata = xmlSchemaTypeAfter.getCachingMetadata();
assertNotNull("No caching metadata", cachingMetadata);
assertNotNull("No retrievalTimestamp", cachingMetadata.getRetrievalTimestamp());
assertNotNull("No serialNumber", cachingMetadata.getSerialNumber());
CachingMetadataType schemaCachingMetadata = xmlSchemaTypeAfter.getCachingMetadata();
assertNotNull("No caching metadata", schemaCachingMetadata);
assertNotNull("No retrievalTimestamp", schemaCachingMetadata.getRetrievalTimestamp());
assertNotNull("No serialNumber", schemaCachingMetadata.getSerialNumber());

Element xsdElement = ObjectTypeUtil.findXsdElement(xmlSchemaTypeAfter);
ResourceSchema parsedSchema = ResourceSchemaImpl.parse(xsdElement, resourceBefore.toString(), prismContext);
assertNotNull("No schema after parsing", parsedSchema);

// schema will be checked in next test
CapabilitiesType capabilitiesRepoAfter = resourceTypeRepoAfter.getCapabilities();
AssertJUnit.assertNotNull("Capabilities missing after test connection.", capabilitiesRepoAfter);
AssertJUnit.assertNotNull("Native capabilities missing after test connection.", capabilitiesRepoAfter.getNative());
AssertJUnit.assertNotNull("Capabilities caching metadata missing after test connection.", capabilitiesRepoAfter.getCachingMetadata());

ResourceType resourceModelAfter = modelService.getObject(ResourceType.class, getResourceOid(), null, null, result).asObjectable();

rememberSteadyResources();

CapabilitiesType capabilitiesModelAfter = resourceModelAfter.getCapabilities();
AssertJUnit.assertNotNull("Capabilities missing after test connection (model)", capabilitiesModelAfter);
AssertJUnit.assertNotNull("Native capabilities missing after test connection (model)", capabilitiesModelAfter.getNative());
AssertJUnit.assertNotNull("Capabilities caching metadata missing after test connection (model)", capabilitiesModelAfter.getCachingMetadata());
}

protected boolean nativeCapabilitiesEntered() {
return false;
}

protected abstract void assertResourceSchemaBeforeTest(Element resourceXsdSchemaElementBefore);

@Test
public void test004Configuration() throws Exception {
final String TEST_NAME = "test004Configuration";
public void test014Configuration() throws Exception {
final String TEST_NAME = "test014Configuration";
displayTestTitle(TEST_NAME);
// GIVEN
OperationResult result = new OperationResult(AbstractManualResourceTest.class.getName()
+ "." + TEST_NAME);

// WHEN
resource = modelService.getObject(ResourceType.class, getResourceOid(), null, null, result);
resourceType = resource.asObjectable();
Expand All @@ -364,15 +392,16 @@ public void test004Configuration() throws Exception {
// PrismContainerDefinition confPropDef = confingurationPropertiesContainer.getDefinition();
// assertNotNull("No configuration properties container definition", confPropDef);

assertSteadyResources();
}

@Test
public void test005ParsedSchema() throws Exception {
final String TEST_NAME = "test005ParsedSchema";
public void test016ParsedSchema() throws Exception {
final String TEST_NAME = "test016ParsedSchema";
displayTestTitle(TEST_NAME);
// GIVEN
OperationResult result = new OperationResult(AbstractManualResourceTest.class.getName() + "." + TEST_NAME);

// THEN
// The returned type should have the schema pre-parsed
assertNotNull(RefinedResourceSchemaImpl.hasParsedSchema(resourceType));
Expand Down Expand Up @@ -410,11 +439,17 @@ public void test005ParsedSchema() throws Exception {
assertTrue("No fullname create", fullnameDef.canAdd());
assertTrue("No fullname update", fullnameDef.canModify());
assertTrue("No fullname read", fullnameDef.canRead());

assertSteadyResources();
}

@Test
public void test006Capabilities() throws Exception {
final String TEST_NAME = "test006Capabilities";
public void test017Capabilities() throws Exception {
final String TEST_NAME = "test017Capabilities";
testCapabilities(TEST_NAME);
}

public void testCapabilities(final String TEST_NAME) throws Exception {
displayTestTitle(TEST_NAME);

// GIVEN
Expand All @@ -424,10 +459,15 @@ public void test006Capabilities() throws Exception {
ResourceType resource = modelService.getObject(ResourceType.class, getResourceOid(), null, null, result).asObjectable();

// THEN
display("Resource from provisioninig", resource);
display("Resource from provisioninig (XML)", PrismTestUtil.serializeObjectToString(resource.asPrismObject(), PrismContext.LANG_XML));
display("Resource from model", resource);
display("Resource from model (XML)", PrismTestUtil.serializeObjectToString(resource.asPrismObject(), PrismContext.LANG_XML));

CapabilityCollectionType nativeCapabilities = resource.getCapabilities().getNative();
assertSteadyResources();

CapabilitiesType capabilities = resource.getCapabilities();
assertNotNull("Missing capability caching metadata", capabilities.getCachingMetadata());

CapabilityCollectionType nativeCapabilities = capabilities.getNative();
List<Object> nativeCapabilitiesList = nativeCapabilities.getAny();
assertFalse("Empty capabilities returned",nativeCapabilitiesList.isEmpty());

Expand All @@ -446,9 +486,87 @@ public void test006Capabilities() throws Exception {
for (Object capability : effectiveCapabilities) {
System.out.println("Capability: "+CapabilityUtil.getCapabilityDisplayName(capability)+" : "+capability);
}

assertSteadyResources();
}

@Test
public void test018ResourceCaching() throws Exception {
final String TEST_NAME = "test018ResourceCaching";
testResourceCaching(TEST_NAME);
}

public void testResourceCaching(final String TEST_NAME) throws Exception {
displayTestTitle(TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();

PrismObject<ResourceType> resourceReadonlyBefore = modelService.getObject(
ResourceType.class, getResourceOid(), GetOperationOptions.createReadOnlyCollection(), task, result);

assertSteadyResources();

// WHEN
displayWhen(TEST_NAME);
PrismObject<ResourceType> resourceReadOnlyAgain = modelService.getObject(
ResourceType.class, getResourceOid(), GetOperationOptions.createReadOnlyCollection(), task, result);

assertSteadyResources();

// WHEN
displayWhen(TEST_NAME);
PrismObject<ResourceType> resourceAgain = modelService.getObject(
ResourceType.class, getResourceOid(), null, task, result);

// THEN
displayThen(TEST_NAME);
assertSuccess(result);

// assertTrue("Resource instance changed", resourceBefore == resourceReadOnlyAgain);

assertSteadyResources();
}

@Test
public void test020ReimportResource() throws Exception {
final String TEST_NAME = "test020ReimportResource";
displayTestTitle(TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();

ImportOptionsType options = new ImportOptionsType();
options.setOverwrite(true);

// WHEN
displayWhen(TEST_NAME);
modelService.importObjectsFromFile(getResourceFile(), options, task, result);

// THEN
displayThen(TEST_NAME);
assertSuccess(result);
}

@Test
public void test022TestConnection() throws Exception {
final String TEST_NAME = "test022TestConnection";
testConnection(TEST_NAME);
}

@Test
public void test027Capabilities() throws Exception {
final String TEST_NAME = "test027Capabilities";
testCapabilities(TEST_NAME);
}

@Test
public void test028ResourceCaching() throws Exception {
final String TEST_NAME = "test028ResourceCaching";
testResourceCaching(TEST_NAME);
}


@Test
public void test100AssignWillRoleOne() throws Exception {
// The count will be checked only after propagation was run, so we can address both direct and grouping cases
Expand Down
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2010-2018 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
*
*/
package com.evolveum.midpoint.model.intest.manual;

import java.io.File;

import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.testng.AssertJUnit;
import org.testng.annotations.Listeners;
import org.w3c.dom.Element;

/**
* @author Radovan Semancik
*/
@ContextConfiguration(locations = {"classpath:ctx-model-intest-test-main.xml"})
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
@Listeners({ com.evolveum.midpoint.tools.testng.AlphabeticalMethodInterceptor.class })
public class TestManualCapabilities extends TestManual {

@Override
protected File getResourceFile() {
return RESOURCE_MANUAL_CAPABILITIES_FILE;
}

@Override
protected boolean nativeCapabilitiesEntered() {
return true;
}

@Override
protected int getNumberOfAccountAttributeDefinitions() {
return 5;
}

}

0 comments on commit 6be4a2f

Please sign in to comment.