Skip to content

Commit

Permalink
Setup for web GUI integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Jan 7, 2016
1 parent 32c2a6c commit f458ced
Show file tree
Hide file tree
Showing 28 changed files with 2,660 additions and 254 deletions.
Expand Up @@ -30,12 +30,15 @@
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.page.PageBase;
import com.evolveum.midpoint.web.util.ModelServiceLocator;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType;

import org.apache.commons.lang.Validate;

import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;

import java.text.DateFormat;
import java.util.*;

Expand All @@ -59,14 +62,14 @@ public class ContainerWrapperFactory {
FocusType.F_LINK_REF);


private PageBase pageBase;
private ModelServiceLocator modelServiceLocator;

private OperationResult result;

public ContainerWrapperFactory(PageBase pageBase) {
Validate.notNull("Page parameter must not be null");
public ContainerWrapperFactory(ModelServiceLocator modelServiceLocator) {
Validate.notNull(modelServiceLocator, "Service locator must not be null");

this.pageBase = pageBase;
this.modelServiceLocator = modelServiceLocator;
}

public OperationResult getResult() {
Expand Down Expand Up @@ -109,7 +112,7 @@ private List<ItemWrapper> createProperties(ContainerWrapper cWrapper, OperationR
PrismReference resourceRef = parent.findReference(ShadowType.F_RESOURCE_REF);
PrismObject<ResourceType> resource = resourceRef.getValue().getObject();

definition = pageBase
definition = modelServiceLocator
.getModelInteractionService()
.getEditObjectClassDefinition((PrismObject<ShadowType>) objectWrapper.getObject(), resource,
AuthorizationPhaseType.REQUEST)
Expand Down

Large diffs are not rendered by default.

Expand Up @@ -76,11 +76,13 @@
import com.evolveum.midpoint.web.security.SecurityUtils;
import com.evolveum.midpoint.web.security.WebApplicationConfiguration;
import com.evolveum.midpoint.web.session.UserProfileStorage;
import com.evolveum.midpoint.web.util.ModelServiceLocator;
import com.evolveum.midpoint.web.util.WebMiscUtil;
import com.evolveum.midpoint.web.util.WebModelUtils;
import com.evolveum.midpoint.web.util.validation.MidpointFormValidatorRegistry;
import com.evolveum.midpoint.wf.api.WorkflowManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.apache.wicket.Component;
Expand All @@ -100,7 +102,7 @@
/**
* @author lazyman
*/
public abstract class PageBase extends PageTemplate {
public abstract class PageBase extends PageTemplate implements ModelServiceLocator {

private static final String DOT_CLASS = PageBase.class.getName() + ".";
private static final String OPERATION_LOAD_USER = DOT_CLASS + "loadUser";
Expand Down Expand Up @@ -192,6 +194,7 @@ public CertificationManager getCertificationManager() {
return certificationManager;
}

@Override
public ModelService getModelService() {
return modelService;
}
Expand All @@ -208,6 +211,7 @@ public SecurityEnforcer getSecurityEnforcer() {
return securityEnforcer;
}

@Override
public ModelInteractionService getModelInteractionService() {
return modelInteractionService;
}
Expand Down
@@ -0,0 +1,31 @@
/**
* Copyright (c) 2016 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.web.util;

import com.evolveum.midpoint.model.api.ModelInteractionService;
import com.evolveum.midpoint.model.api.ModelService;

/**
* @author semancik
*
*/
public interface ModelServiceLocator {

ModelService getModelService();

ModelInteractionService getModelInteractionService();

}
Expand Up @@ -16,11 +16,29 @@

package com.evolveum.midpoint.web;

import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNull;
import static com.evolveum.midpoint.web.AdminGuiTestConstants.*;

import com.evolveum.midpoint.model.api.ModelInteractionService;
import com.evolveum.midpoint.model.api.ModelService;
import com.evolveum.midpoint.model.test.AbstractModelIntegrationTest;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.AbstractIntegrationTest;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.page.PageBase;
import com.evolveum.midpoint.web.security.MidPointApplication;
import com.evolveum.midpoint.web.util.ModelServiceLocator;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

import org.apache.wicket.Application;
import org.apache.wicket.ThreadContext;
import org.apache.wicket.protocol.http.WebApplication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.AfterClass;
Expand All @@ -29,21 +47,37 @@
import org.testng.annotations.BeforeMethod;

import java.io.File;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Set;

import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

/**
* @author lazyman
* @author semancik
*/
public abstract class AbstractGuiIntegrationTest extends AbstractIntegrationTest {
public abstract class AbstractGuiIntegrationTest extends AbstractModelIntegrationTest {

private static final Trace LOGGER = TraceManager.getTrace(AbstractGuiIntegrationTest.class);

public static final File FOLDER_BASIC = new File("./src/test/resources/basic");

@Autowired
protected PrismContext prismContext;

@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);
}

@BeforeClass
@BeforeClass
public void beforeClass() throws Exception {
System.out.println("\n>>>>>>>>>>>>>>>>>>>>>>>> START " + getClass().getName() + "<<<<<<<<<<<<<<<<<<<<<<<<");
LOGGER.info("\n>>>>>>>>>>>>>>>>>>>>>>>> START {} <<<<<<<<<<<<<<<<<<<<<<<<", new Object[]{getClass().getName()});
Expand All @@ -66,4 +100,50 @@ public void afterMethod(Method method) {
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>> END TEST" + getClass().getName() + "." + method.getName() + "<<<<<<<<<<<<<<<<<<<<<<<<");
LOGGER.info(">>>>>>>>>>>>>>>>>>>>>>>> END {}.{} <<<<<<<<<<<<<<<<<<<<<<<<", new Object[]{getClass().getName(), method.getName()});
}

protected ModelServiceLocator getServiceLocator() {
return new ModelServiceLocator() {

@Override
public ModelService getModelService() {
return modelService;
}

@Override
public ModelInteractionService getModelInteractionService() {
return modelInteractionService;
}
};
}


protected void assertUserJack(PrismObject<UserType> user) {
assertUserJack(user, USER_JACK_FULL_NAME, USER_JACK_GIVEN_NAME, USER_JACK_FAMILY_NAME);
}

protected void assertUserJack(PrismObject<UserType> user, String fullName) {
assertUserJack(user, fullName, USER_JACK_GIVEN_NAME, USER_JACK_FAMILY_NAME);
}

protected void assertUserJack(PrismObject<UserType> user, String fullName, String givenName, String familyName) {
assertUserJack(user, fullName, givenName, familyName, "Caribbean");
}

protected void assertUserJack(PrismObject<UserType> user, String fullName, String givenName, String familyName, String locality) {
assertUserJack(user, USER_JACK_USERNAME, fullName, givenName, familyName, locality);
}

protected void assertUserJack(PrismObject<UserType> user, String name, String fullName, String givenName, String familyName, String locality) {
assertUser(user, USER_JACK_OID, name, fullName, givenName, familyName, locality);
UserType userType = user.asObjectable();
PrismAsserts.assertEqualsPolyString("Wrong jack honorificPrefix", "Cpt.", userType.getHonorificPrefix());
assertEquals("Wrong jack employeeNumber", "001", userType.getEmployeeNumber());
assertEquals("Wrong jack employeeType", "CAPTAIN", userType.getEmployeeType().get(0));
if (locality == null) {
assertNull("Locality sneaked to user jack", userType.getLocality());
} else {
PrismAsserts.assertEqualsPolyString("Wrong jack locality", locality, userType.getLocality());
}
}

}
Expand Up @@ -16,6 +16,8 @@

package com.evolveum.midpoint.web;

import com.evolveum.midpoint.model.api.ModelInteractionService;
import com.evolveum.midpoint.model.api.ModelService;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.schema.MidPointPrismContextFactory;
import com.evolveum.midpoint.schema.constants.MidPointConstants;
Expand All @@ -24,6 +26,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.web.util.ModelServiceLocator;

import java.io.File;
import java.io.IOException;
Expand All @@ -38,15 +41,25 @@ public abstract class AbstractGuiUnitTest {

private static final Trace LOGGER = TraceManager.getTrace(AbstractGuiUnitTest.class);

public static final String COMMON_DIR_NAME = "common";
public static final File COMMON_DIR = new File(MidPointTestConstants.TEST_RESOURCES_DIR, COMMON_DIR_NAME);

public static final File USER_JACK_FILE = new File(COMMON_DIR, "user-jack.xml");

@BeforeSuite
public void setup() throws SchemaException, SAXException, IOException {
PrettyPrinter.setDefaultNamespacePrefix(MidPointConstants.NS_MIDPOINT_PUBLIC_PREFIX);
PrismTestUtil.resetPrismContext(MidPointPrismContextFactory.FACTORY);
}

protected ModelServiceLocator getServiceLocator() {
return new ModelServiceLocator() {

@Override
public ModelService getModelService() {
return null;
}

@Override
public ModelInteractionService getModelInteractionService() {
return null;
}
};
}

}
@@ -0,0 +1,104 @@
/**
* Copyright (c) 2016 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.web;

import static org.testng.AssertJUnit.assertNotNull;
import static com.evolveum.midpoint.test.IntegrationTestTools.display;
import static com.evolveum.midpoint.web.AdminGuiTestConstants.*;

import org.testng.annotations.Test;

import com.evolveum.icf.dummy.resource.DummyResource;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.DummyResourceContoller;
import com.evolveum.midpoint.test.IntegrationTestTools;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

/**
* @author semancik
*
*/
public abstract class AbstractInitializedGuiIntegrationTest extends AbstractGuiIntegrationTest {

private static final Trace LOGGER = TraceManager.getTrace(AbstractInitializedGuiIntegrationTest.class);

protected DummyResource dummyResource;
protected DummyResourceContoller dummyResourceCtl;
protected ResourceType resourceDummyType;
protected PrismObject<ResourceType> resourceDummy;

protected PrismObject<UserType> userAdministrator;
protected String accountJackOid;

/* (non-Javadoc)
* @see com.evolveum.midpoint.test.AbstractIntegrationTest#initSystem(com.evolveum.midpoint.task.api.Task, com.evolveum.midpoint.schema.result.OperationResult)
*/
@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
LOGGER.trace("initSystem");
super.initSystem(initTask, initResult);

modelService.postInit(initResult);
userAdministrator = repositoryService.getObject(UserType.class, USER_ADMINISTRATOR_OID, null, initResult);
login(userAdministrator);

dummyResourceCtl = DummyResourceContoller.create(null);
dummyResourceCtl.extendSchemaPirate();
dummyResource = dummyResourceCtl.getDummyResource();
resourceDummy = importAndGetObjectFromFile(ResourceType.class, RESOURCE_DUMMY_FILE, RESOURCE_DUMMY_OID, initTask, initResult);
resourceDummyType = resourceDummy.asObjectable();
dummyResourceCtl.setResource(resourceDummy);

repoAddObjectFromFile(USER_JACK_FILE, UserType.class, true, initResult);

}

@Test
public void test000PreparationAndSanity() throws Exception {
final String TEST_NAME = "test100GetResourceDummy";
TestUtil.displayTestTile(this, TEST_NAME);

// GIVEN
Task task = taskManager.createTaskInstance(AbstractInitializedGuiIntegrationTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();

assertNotNull("No model service", modelService);

// WHEN
TestUtil.displayWhen(TEST_NAME);
assignAccount(USER_JACK_OID, RESOURCE_DUMMY_OID, null, task, result);

// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
IntegrationTestTools.display(result);
TestUtil.assertSuccess(result);

PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
assertUserJack(userJack);
accountJackOid = getSingleLinkOid(userJack);

}

}

0 comments on commit f458ced

Please sign in to comment.