org.glassfish.jersey.test.JerseyTest Java Examples

The following examples show how to use org.glassfish.jersey.test.JerseyTest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Util.java    From tessera with Apache License 2.0 6 votes vote down vote up
public static JerseyTest create(Enclave enclave) {

        SLF4JBridgeHandler.removeHandlersForRootLogger();
        SLF4JBridgeHandler.install();

        return new JerseyTest() {
            @Override
            protected Application configure() {
                
                enable(TestProperties.LOG_TRAFFIC);
                enable(TestProperties.DUMP_ENTITY);
                set(TestProperties.CONTAINER_PORT, SocketUtils.findAvailableTcpPort());
                EnclaveApplication application = new EnclaveApplication(new EnclaveResource(enclave));

                ResourceConfig config = ResourceConfig.forApplication(application);
                config.packages("com.quorum.tessera.enclave.rest");
                return config;
            }

        };
    }
 
Example #2
Source File: Q2TRestAppTest.java    From tessera with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {

    final Set services = new HashSet();
    services.add(mock(TransactionManager.class));

    serviceLocator = (MockServiceLocator) ServiceLocator.create();
    serviceLocator.setServices(services);

    q2TRestApp = new Q2TRestApp();

    jersey =
            new JerseyTest() {
                @Override
                protected Application configure() {
                    enable(TestProperties.LOG_TRAFFIC);
                    enable(TestProperties.DUMP_ENTITY);
                    ResourceConfig jerseyconfig = ResourceConfig.forApplication(q2TRestApp);
                    return jerseyconfig;
                }
            };

    jersey.setUp();
}
 
Example #3
Source File: ThirdPartyRestAppTest.java    From tessera with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    serviceLocator = (MockServiceLocator) ServiceLocator.create();

    Set services = new HashSet();
    services.add(mock(IPWhitelistFilter.class));
    services.add(mock(TransactionManager.class));
    services.add(mock(PartyInfoService.class));

    serviceLocator.setServices(services);

    thirdParty = new ThirdPartyRestApp();

    jersey =
            new JerseyTest() {
                @Override
                protected Application configure() {
                    enable(TestProperties.LOG_TRAFFIC);
                    enable(TestProperties.DUMP_ENTITY);
                    ResourceConfig jerseyconfig = ResourceConfig.forApplication(thirdParty);
                    return jerseyconfig;
                }
            };
    jersey.setUp();
}
 
Example #4
Source File: GatewayBinaryResponseFilterIntTest.java    From jrestless with Apache License 2.0 6 votes vote down vote up
private JerseyTest createJerseyTest(Boolean binaryCompressionOnly) {
	return new JerseyTest() {
		@Override
		protected Application configure() {
			ResourceConfig config = new ResourceConfig();
			config.register(TestResource.class);
			config.register(EncodingFilter.class);
			config.register(GZipEncoder.class);
			config.register(GatewayBinaryResponseFilter.class);
			if (binaryCompressionOnly != null) {
				config.property(GatewayBinaryResponseFilter.BINARY_COMPRESSION_ONLY_PROPERTY,
						binaryCompressionOnly);
			}
			return config;
		}
	};
}
 
Example #5
Source File: RxJerseyTest.java    From rx-jersey with MIT License 6 votes vote down vote up
@Override
protected Application configure() {
    ResourceConfig resourceConfig = new ResourceConfig()
            .register(InjectTestFeature.class)
            .register(JacksonFeature.class)
            .register(RxJerseyClientFeature.class)
            .register(ServerResource.class)
            .register(new AbstractBinder() {
                @Override
                protected void configure() {
                    bind(RxJerseyTest.this).to(JerseyTest.class);
                }
            });

    configure(resourceConfig);

    return resourceConfig;
}
 
Example #6
Source File: RxJerseyTest.java    From rx-jersey with MIT License 6 votes vote down vote up
@Override
protected Application configure() {
    ResourceConfig resourceConfig = new ResourceConfig()
            .register(InjectTestFeature.class)
            .register(JacksonFeature.class)
            .register(RxJerseyClientFeature.class)
            .register(ServerResource.class)
            .register(new AbstractBinder() {
                @Override
                protected void configure() {
                    bind(RxJerseyTest.this).to(JerseyTest.class);
                }
            });

    configure(resourceConfig);

    return resourceConfig;
}
 
Example #7
Source File: P2PRestAppTest.java    From tessera with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {

    Set services = new HashSet<>();
    services.add(mock(PartyInfoService.class));
    services.add(mock(TransactionManager.class));
    services.add(mock(Enclave.class));

    Client client = mock(Client.class);
    when(runtimeContext.getP2pClient()).thenReturn(client);
    when(runtimeContext.isRemoteKeyValidation()).thenReturn(true);


    MockServiceLocator serviceLocator = (MockServiceLocator) ServiceLocator.create();
    serviceLocator.setServices(services);

    p2PRestApp = new P2PRestApp();

    jersey =
        new JerseyTest() {
            @Override
            protected Application configure() {
                enable(TestProperties.LOG_TRAFFIC);
                enable(TestProperties.DUMP_ENTITY);
                ResourceConfig jerseyconfig = ResourceConfig.forApplication(p2PRestApp);
                return jerseyconfig;
            }
        };

    jersey.setUp();
}
 
Example #8
Source File: JerseySpringTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Autowired
public void setApplicationContext(final ApplicationContext context) {
    _jerseyTest = new JerseyTest() {
        @Override
        protected Application configure() {
            ResourceConfig application = new ManagementApplication();
            application.register(AuthenticationFilter.class);
            application.property("contextConfig", context);

            return application;
        }
    };
}
 
Example #9
Source File: JerseySpringTest.java    From gravitee-management-rest-api with Apache License 2.0 5 votes vote down vote up
@Autowired
public void setApplicationContext(final ApplicationContext context)
{
    _jerseyTest = new JerseyTest()
    {
        
        @Override
        protected Application configure()
        {
            // Find first available port.
            forceSet(TestProperties.CONTAINER_PORT, "0");

            ResourceConfig application = new GraviteeManagementApplication(authenticationProviderManager);

            application.property("contextConfig", context);
            decorate(application);

            return application;
        }

        @Override
        protected void configureClient(ClientConfig config) {
            super.configureClient(config);

            config.register(ObjectMapperResolver.class);
            config.register(MultiPartFeature.class);
            config.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);

        }
    };
}
 
Example #10
Source File: JerseySpringTest.java    From gravitee-management-rest-api with Apache License 2.0 5 votes vote down vote up
@Autowired
public void setApplicationContext(final ApplicationContext context)
{
    _jerseyTest = new JerseyTest()
    {
        @Override
        protected Application configure()
        {
            // Find first available port.
            forceSet(TestProperties.CONTAINER_PORT, "0");

            ResourceConfig application = new GraviteePortalApplication(authenticationProviderManager);

            application.property("contextConfig", context);
            decorate(application);

            return application;
        }

        @Override
        protected void configureClient(ClientConfig config) {
            super.configureClient(config);

            config.register(ObjectMapperResolver.class);
            config.register(MultiPartFeature.class);
        }
    };
}
 
Example #11
Source File: AuthenticationEndpointTest.java    From divide with Apache License 2.0 5 votes vote down vote up
public static synchronized Credentials signUpUser(JerseyTest test) throws Exception{
    PublicKey publicKey = getPublicKey(test);
    Credentials signInUser = TestUtils.getTestUser();
    signInUser.encryptPassword(publicKey);
    String user = test.target("/auth").request().post(TestUtils.toEntity(signInUser), String.class);
    Credentials returnedUser = TestUtils.getGson().fromJson(user,Credentials.class);

    assertEquals(signInUser.getUsername(), returnedUser.getUsername());
    return returnedUser;
}
 
Example #12
Source File: PushEndpointTest.java    From divide with Apache License 2.0 5 votes vote down vote up
private Response registerToken(Credentials user, PublicKey key, JerseyTest test){
    EncryptedEntity.Writter entity = new EncryptedEntity.Writter(key);
    entity.put("token", "whatwhat");

    Response response = target("/push")
            .request()
            .header(ContainerRequest.AUTHORIZATION, "CUSTOM " + user.getAuthToken())
            .buildPost(TestUtils.toEntity(entity)).invoke();
    int statusCode = response.getStatus();
    assertEquals(200,statusCode);
    return response;
}
 
Example #13
Source File: EmbeddedServerTestHarness.java    From rest-utils with Apache License 2.0 5 votes vote down vote up
protected JerseyTest getJerseyTest() {
  // This is instantiated on demand since we need subclasses to register the resources they need
  // passed along, but JerseyTest calls configure() from its constructor.
  if (test == null) {
    test = new JettyJerseyTest();
  }
  return test;
}
 
Example #14
Source File: AuthenticationEndpointTest.java    From divide with Apache License 2.0 4 votes vote down vote up
public static synchronized PublicKey getPublicKey(JerseyTest test) throws Exception{
        String publicKeyBytes = test.target("/auth/key").request().get(String.class);
        byte[] bytes = TestUtils.getGson().fromJson(publicKeyBytes,byte[].class);
    return Crypto.pubKeyFromBytes(bytes);
}
 
Example #15
Source File: DynamicJerseyTestRunner.java    From jrestless with Apache License 2.0 3 votes vote down vote up
/**
 * <ol>
 * <li>calls {@link JerseyTest#setUp()}
 * <li>passes the initialized JerseyTest to the consumer.
 * <li>calls {@link JerseyTest#tearDown()}
 * </ol>
 *
 * @param jerseyTest
 * @param test
 * @throws Exception
 */
public void runJerseyTest(JerseyTest jerseyTest, ThrowingConsumer<JerseyTest> test) throws Exception {
	try {
		jerseyTest.setUp();
		test.accept(jerseyTest);
	} finally {
		jerseyTest.tearDown();
	}
}