Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 0eb8589

Browse files
author
Michal Gajdos
committed
Fixed examples whose tests were failing on GF.
Change-Id: Ie8b41dee127320500b05e376f0663377098435f7 Signed-off-by: Michal Gajdos <[email protected]>
1 parent f879e98 commit 0eb8589

File tree

5 files changed

+23
-30
lines changed

5 files changed

+23
-30
lines changed

examples/bean-validation-webapp/src/main/java/org/glassfish/jersey/examples/beanvalidation/webapp/MyApplication.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2012-2015 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -58,6 +58,9 @@
5858
import org.glassfish.jersey.server.validation.ValidationConfig;
5959
import org.glassfish.jersey.server.validation.internal.InjectingConstraintValidatorFactory;
6060

61+
import org.eclipse.persistence.jaxb.BeanValidationMode;
62+
import org.eclipse.persistence.jaxb.MarshallerProperties;
63+
6164
/**
6265
* ContactCard application configuration.
6366
*
@@ -74,7 +77,10 @@ public MyApplication() {
7477

7578
// Providers - JSON.
7679
register(MoxyJsonFeature.class);
77-
register(JsonConfiguration.class);
80+
register(new MoxyJsonConfig().setFormattedOutput(true)
81+
// Turn off BV otherwise the entities on server would be validated by MOXy as well.
82+
.property(MarshallerProperties.BEAN_VALIDATION_MODE, BeanValidationMode.NONE)
83+
.resolver());
7884
}
7985

8086
/**
@@ -123,17 +129,4 @@ public List<String> getParameterNames(final Method method) {
123129
}
124130
}
125131
}
126-
127-
/**
128-
* Configuration for {@link org.eclipse.persistence.jaxb.rs.MOXyJsonProvider} - outputs formatted JSON.
129-
*/
130-
public static class JsonConfiguration implements ContextResolver<MoxyJsonConfig> {
131-
132-
@Override
133-
public MoxyJsonConfig getContext(final Class<?> type) {
134-
final MoxyJsonConfig config = new MoxyJsonConfig();
135-
config.setFormattedOutput(true);
136-
return config;
137-
}
138-
}
139132
}

examples/bean-validation-webapp/src/test/java/org/glassfish/jersey/examples/beanvalidation/webapp/ContactCardTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ protected Application configure() {
9393
enable(TestProperties.LOG_TRAFFIC);
9494
enable(TestProperties.DUMP_ENTITY);
9595

96-
final MyApplication application = new MyApplication();
97-
application.property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
98-
return application;
96+
return new MyApplication().property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
9997
}
10098

10199
@Override

examples/rx-client-java8-webapp/src/test/java/org/glassfish/jersey/examples/rx/RxClientsTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@
4747
import org.glassfish.jersey.test.JerseyTest;
4848
import org.glassfish.jersey.test.ServletDeploymentContext;
4949

50-
import org.junit.FixMethodOrder;
5150
import org.junit.Test;
52-
import org.junit.runners.MethodSorters;
5351
import static org.hamcrest.CoreMatchers.is;
5452
import static org.hamcrest.MatcherAssert.assertThat;
5553

@@ -62,7 +60,8 @@ public class RxClientsTest extends JerseyTest {
6260

6361
@Override
6462
protected DeploymentContext configureDeployment() {
65-
return ServletDeploymentContext.builder(RxApplication.class).contextPath("rx").build();
63+
return ServletDeploymentContext.builder(RxApplication.class)
64+
.contextPath("rx-client-java8-webapp").contextPath("rx").build();
6665
}
6766

6867
@Test

examples/rx-client-webapp/src/test/java/org/glassfish/jersey/examples/rx/RxClientsTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2014-2015 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -63,7 +63,8 @@ public class RxClientsTest extends JerseyTest {
6363

6464
@Override
6565
protected DeploymentContext configureDeployment() {
66-
return ServletDeploymentContext.builder(RxApplication.class).contextPath("rx").build();
66+
return ServletDeploymentContext.builder(RxApplication.class)
67+
.contextPath("rx-client-webapp").servletPath("rx").build();
6768
}
6869

6970
@Test

examples/shortener-webapp/src/test/java/org/glassfish/jersey/examples/shortener/webapp/ResourcesTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import java.util.List;
4747

4848
import javax.ws.rs.client.Entity;
49-
import javax.ws.rs.core.Application;
5049
import javax.ws.rs.core.Form;
5150
import javax.ws.rs.core.HttpHeaders;
5251
import javax.ws.rs.core.MediaType;
@@ -55,13 +54,15 @@
5554
import org.glassfish.jersey.examples.shortener.webapp.domain.ShortenedLink;
5655
import org.glassfish.jersey.examples.shortener.webapp.service.ShortenerService;
5756
import org.glassfish.jersey.server.validation.ValidationError;
57+
import org.glassfish.jersey.test.DeploymentContext;
5858
import org.glassfish.jersey.test.JerseyTest;
59+
import org.glassfish.jersey.test.ServletDeploymentContext;
5960
import org.glassfish.jersey.test.TestProperties;
6061

61-
import org.junit.Assert;
6262
import org.junit.Test;
6363
import static org.hamcrest.CoreMatchers.equalTo;
6464
import static org.hamcrest.MatcherAssert.assertThat;
65+
import static org.junit.Assert.assertTrue;
6566

6667
import com.github.mustachejava.DefaultMustacheFactory;
6768
import com.github.mustachejava.MustacheFactory;
@@ -74,19 +75,20 @@ public class ResourcesTest extends JerseyTest {
7475
private static final MustacheFactory factory = new DefaultMustacheFactory();
7576

7677
@Override
77-
protected Application configure() {
78+
protected DeploymentContext configureDeployment() {
7879
enable(TestProperties.DUMP_ENTITY);
7980
enable(TestProperties.LOG_TRAFFIC);
8081

81-
return new ShortenerApplication();
82+
return ServletDeploymentContext.builder(ShortenerApplication.class)
83+
.contextPath("shortener-webapp").servletPath("/").build();
8284
}
8385

8486
@Test
8587
public void testCreateForm() throws Exception {
8688
final Response response = target().request("text/html").get();
8789

8890
assertThat(response.getStatus(), equalTo(200));
89-
Assert.assertTrue(response.getMediaType().isCompatible(MediaType.TEXT_HTML_TYPE));
91+
assertTrue(response.getMediaType().isCompatible(MediaType.TEXT_HTML_TYPE));
9092

9193
assertThat(response.readEntity(String.class),
9294
equalTo(resolveTemplate("mustache/form.mustache", Collections.singletonMap("greeting", "Link Shortener"))));
@@ -98,7 +100,7 @@ public void testCreateLink() throws Exception {
98100
final Response response = target().request("text/html").post(Entity.form(form));
99101

100102
assertThat(response.getStatus(), equalTo(200));
101-
Assert.assertTrue(response.getMediaType().isCompatible(MediaType.TEXT_HTML_TYPE));
103+
assertTrue(response.getMediaType().isCompatible(MediaType.TEXT_HTML_TYPE));
102104

103105
assertThat(response.readEntity(String.class),
104106
equalTo(resolveTemplate("mustache/short-link.mustache",
@@ -111,7 +113,7 @@ public void testCreateInvalidLink() throws Exception {
111113
final Response response = target().request("text/html").post(Entity.form(form));
112114

113115
assertThat(response.getStatus(), equalTo(400));
114-
Assert.assertTrue(response.getMediaType().isCompatible(MediaType.TEXT_HTML_TYPE));
116+
assertTrue(response.getMediaType().isCompatible(MediaType.TEXT_HTML_TYPE));
115117

116118
assertThat(response.readEntity(String.class),
117119
equalTo(resolveTemplate("mustache/error-form.mustache", getCreateFormValidationErrors())));

0 commit comments

Comments
 (0)