Skip to content

Commit

Permalink
Provide web integration test infrastructure #1778
Browse files Browse the repository at this point in the history
  • Loading branch information
jreznot committed May 26, 2019
1 parent 94d272e commit fca4f57
Show file tree
Hide file tree
Showing 75 changed files with 1,336 additions and 346 deletions.
19 changes: 18 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def webModule = project(':cuba-web')

def coreTestsModule = project(':cuba-core-tests')
def clientTestsModule = project(':cuba-client-tests')
def webTestsModule = project(':cuba-web-tests')

configure([sharedLibModule, globalModule, coreModule, clientModule, guiModule,
webModule, desktopModule, portalModule]) {
Expand Down Expand Up @@ -605,6 +606,20 @@ configure(webWidgetsModule) {
}
}

configure(webTestsModule) {
apply(plugin: 'java')
apply(plugin: 'maven')
apply(plugin: 'cuba')

dependencies {
compile(clientTestsModule)
compile(webModule)

compile(bom['junit:junit'])
compile(bom['javax.servlet:javax.servlet-api'])
}
}

configure(webModule) {
configurations {
themes
Expand Down Expand Up @@ -634,10 +649,12 @@ configure(webModule) {
themes(bom['com.vaadin:vaadin-themes'])

testCompile('cglib:cglib-nodep:3.2.6')
testRuntime(bom['javax.servlet:javax.servlet-api'])

testCompile(clientTestsModule)
// prevent cyclic dependencies
testCompile(webTestsModule.sourceSets.main.output)
testCompile(guiModule.sourceSets.test.output)
testRuntime(bom['javax.servlet:javax.servlet-api'])
}

test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
import static com.haulmont.cuba.core.sys.serialization.SerializationSupport.serialize;

public class TestSupport {

@SuppressWarnings("unchecked")
public static <T> T reserialize(Serializable object) {
if (object == null)
if (object == null) {
return null;
}

return (T) deserialize(serialize(object));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ public void removePermission(PermissionType type, String target) {
permissions[type.ordinal()].remove(target);
}

/**
* INTERNAL
*/
public void removePermissions(PermissionType type) {
permissions[type.ordinal()].clear();
}

/**
* INTERNAL
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,8 @@ public static class ResolvedWindowInfo extends WindowInfo {
protected final Class<? extends FrameOwner> controllerClass;
protected final Type type;

public ResolvedWindowInfo(WindowInfo windowInfo, Type type, Class<? extends FrameOwner> controllerClass, String template) {
public ResolvedWindowInfo(WindowInfo windowInfo, Type type, Class<? extends FrameOwner> controllerClass,
String template) {
super(windowInfo.getId(), null, windowInfo.getDescriptor(),
windowInfo.getControllerClassName(), windowInfo.getRouteDefinition());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public UiControllersConfiguration() {
}

@Inject
protected void setApplicationContext(ApplicationContext applicationContext) {
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}

Expand Down
53 changes: 53 additions & 0 deletions modules/web-tests/src/com/haulmont/cuba/web/AppTestUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2008-2019 Haulmont.
*
* 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.haulmont.cuba.web;

import com.haulmont.cuba.core.global.Events;
import com.haulmont.cuba.gui.theme.ThemeConstants;
import com.haulmont.cuba.web.sys.AppCookies;
import com.vaadin.server.VaadinRequest;
import org.springframework.context.ApplicationContext;

public final class AppTestUtils {

private AppTestUtils() {
}

public static void setThemeConstants(App app, ThemeConstants themeConstants) {
app.themeConstants = themeConstants;
}

public static void setCookies(App app, AppCookies appCookies) {
app.cookies = appCookies;
}

public static void setConnection(App app, Connection connection) {
app.connection = connection;
}

public static void setEvents(App app, Events events) {
app.events = events;
}

public static void setApplicationContext(AppUI ui, ApplicationContext context) {
ui.setApplicationContext(context);
}

public static void initUi(AppUI ui, VaadinRequest request) {
ui.init(request);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008-2018 Haulmont.
* Copyright (c) 2008-2019 Haulmont.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,6 +31,9 @@
import com.haulmont.cuba.core.sys.remoting.LocalServiceDirectory;
import com.haulmont.cuba.gui.AppConfig;
import com.haulmont.cuba.web.sys.remoting.WebRemoteProxyBeanCreator;
import com.haulmont.cuba.web.testsupport.proxy.ConfigStorageServiceProxy;
import com.haulmont.cuba.web.testsupport.proxy.DataServiceProxy;
import com.haulmont.cuba.web.testsupport.proxy.TestServiceProxy;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringSubstitutor;
import org.apache.commons.text.StringTokenizer;
Expand Down Expand Up @@ -86,16 +89,19 @@ public void after() {
public TestContainer() {
String property = System.getProperty("logback.configurationFile");
if (StringUtils.isBlank(property)) {
System.setProperty("logback.configurationFile", "com/haulmont/cuba/web/testsupport/test-web-logback.xml");
System.setProperty("logback.configurationFile", getLogbackConfigLocation());
}
log = LoggerFactory.getLogger(TestContainer.class);

springConfig = "com/haulmont/cuba/web/testsupport/test-web-spring.xml";
appComponents = Collections.emptyList();
appPropertiesFiles = Arrays.asList(
"com/haulmont/cuba/web-app.properties",
"com/haulmont/cuba/web/testsupport/test-web-app.properties",
"com/haulmont/cuba/test-web-app.properties");
"com/haulmont/cuba/web/testsupport/test-web-app.properties");
}

protected String getLogbackConfigLocation() {
return "com/haulmont/cuba/web/testsupport/test-web-logback.xml";
}

public void setupLogging(String logger, Level level) {
Expand Down Expand Up @@ -247,7 +253,9 @@ protected void initAppContext() {

StringTokenizer tokenizer = new StringTokenizer(configProperty);
List<String> locations = tokenizer.getTokenList();
locations.add(getSpringConfig());

StringTokenizer configTokenizer = new StringTokenizer(getSpringConfig());
locations.addAll(configTokenizer.getTokenList());

springAppContext = new CubaClassPathXmlApplicationContext(locations.toArray(new String[0]));
AppContext.Internals.setApplicationContext(springAppContext);
Expand All @@ -269,4 +277,4 @@ protected void setupContext() {
AppContext.setProperty(entry.getKey(), entry.getValue());
}
}
}
}
Loading

0 comments on commit fca4f57

Please sign in to comment.