org.mockserver.model.StringBody Java Examples

The following examples show how to use org.mockserver.model.StringBody. 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: OdooXmlRpcProxyTest.java    From openerp-java-api with Apache License 2.0 6 votes vote down vote up
@Test
public void should_return_server_version() throws Exception {
	// Make sure SSL works by adding MockServer CA certificate to context
	SSLSocketFactory previousFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
	HttpsURLConnection.setDefaultSSLSocketFactory(SSLFactory.getInstance().sslContext().getSocketFactory());
	ClientAndServer mockServer = ClientAndServer.startClientAndServer(port);
	try {
		// Given: the server expects a request of its version
		mockServer
				.when(request().withMethod("POST").withPath("/xmlrpc/2/db")
						.withBody(new StringBody(
								"<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodCall><methodName>server_version</methodName><params/></methodCall>")))
				.respond(response().withStatusCode(200).withBody(
						"<?xml version='1.0'?>\n<methodResponse>\n<params>\n<param>\n<value><string>9.0e</string></value>\n</param>\n</params>\n</methodResponse>\n"));

		// When: Server version is requested
		Version version = OdooXmlRpcProxy.getServerVersion(RPCProtocol.RPC_HTTPS, host, port);

		// Then: the server version is returned
		assertThat(version).as("Server version").isNotNull().hasToString("9.0e");
	} finally {
		mockServer.stop();
		HttpsURLConnection.setDefaultSSLSocketFactory(previousFactory);
	}

}
 
Example #2
Source File: AbstractS3ClientTest.java    From vertx-s3-client with Apache License 2.0 5 votes vote down vote up
void mockGetObjectAcl(AccessControlPolicy accessControlPolicy, Header... expectedHeaders) throws IOException {
    mock(
            ImmutableMap.of("acl", ImmutableList.of("")),
            "GET",
            "/bucket/key",
            200,
            null,
            new StringBody("<AccessControlPolicy><Owner><ID>" + accessControlPolicy.getOwner().getId() + "</ID><DisplayName>" + accessControlPolicy.getOwner().getDisplayName() + "</DisplayName></Owner>" +
                    "<AccessControlList><Grant><Grantee><ID>" + accessControlPolicy.getGrants().get(0).getGrantee().getId() + "</ID><DisplayName>" + accessControlPolicy.getGrants().get(0).getGrantee().getDisplayName() + "</DisplayName></Grantee><Permission>" + accessControlPolicy.getGrants().get(0).getPermission() + "</Permission></Grant></AccessControlList></AccessControlPolicy>"
            ),
            Collections.emptyList(),
            expectedHeaders
    );
}
 
Example #3
Source File: AbstractS3ClientTest.java    From vertx-s3-client with Apache License 2.0 5 votes vote down vote up
void mockPutObject(Header... expectedHeaders) throws IOException {
    mock(
            Collections.emptyMap(),
            "PUT",
            "/bucket/key",
            200,
            new StringBody("test"),
            new StringBody("<>"),
            Collections.emptyList(),
            expectedHeaders
    );
}
 
Example #4
Source File: AbstractS3ClientTest.java    From vertx-s3-client with Apache License 2.0 5 votes vote down vote up
void mockPutObjectErrorResponse(Header... expectedHeaders) throws IOException {
    mock(
            Collections.emptyMap(),
            "PUT",
            "/bucket/key",
            403,
            new StringBody("test"),
            new BinaryBody(Resources.toByteArray(Resources.getResource(AbstractS3ClientTest.class, "/response/errorResponse.xml"))),
            Collections.emptyList(),
            expectedHeaders
    );
}
 
Example #5
Source File: AbstractS3ClientTest.java    From vertx-s3-client with Apache License 2.0 5 votes vote down vote up
void mockPutObjectAclWithBody(AccessControlPolicy accessControlPolicy, Header... expectedHeaders) throws IOException {
    mock(
            ImmutableMap.of("acl", ImmutableList.of("")),
            "PUT",
            "/bucket/key",
            200,
            new XmlBody("<AccessControlPolicy><Owner><ID>" + accessControlPolicy.getOwner().getId() + "</ID><DisplayName>" + accessControlPolicy.getOwner().getDisplayName() + "</DisplayName></Owner>" +
                    "<AccessControlList><Grant><Grantee><ID>" + accessControlPolicy.getGrants().get(0).getGrantee().getId() + "</ID><DisplayName>" + accessControlPolicy.getGrants().get(0).getGrantee().getDisplayName() + "</DisplayName></Grantee><Permission>" + accessControlPolicy.getGrants().get(0).getPermission() + "</Permission></Grant></AccessControlList></AccessControlPolicy>"
            ),
            new StringBody("<>"),
            Collections.emptyList(),
            expectedHeaders
    );
}
 
Example #6
Source File: SessionTest.java    From openerp-java-api with Apache License 2.0 5 votes vote down vote up
private static void mockDeniedDatabaseListing() {
	mockServer
			.when(request().withMethod("POST").withPath("/xmlrpc/2/db")
					.withBody(new StringBody(
							"<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodCall><methodName>list</methodName><params/></methodCall>")))
			.respond(response().withStatusCode(200).withBody(
					"<?xml version='1.0'?>\n<methodResponse>\n<fault>\n<value><struct>\n<member>\n<name>faultCode</name>\n<value><int>3</int></value>\n</member>\n<member>\n<name>faultString</name>\n<value><string>Access denied</string></value>\n</member>\n</struct></value>\n</fault>\n</methodResponse>\n"));
}
 
Example #7
Source File: SessionTest.java    From openerp-java-api with Apache License 2.0 5 votes vote down vote up
private static void mockAllowedDatabaseListing() {
	mockServer
			.when(request().withMethod("POST").withPath("/xmlrpc/2/db")
					.withBody(new StringBody(
							"<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodCall><methodName>list</methodName><params/></methodCall>")))
			.respond(response().withStatusCode(200).withBody(
					"<?xml version='1.0'?>\n<methodResponse>\n<params>\n<param>\n<value>\n<array>\n<data>\n<value><string>"
							+ MOCK_DATABASE_NAME
							+ "</string></value>\n</data>\n</array>\n</value>\n</param>\n</params>\n</methodResponse>\n"));
}
 
Example #8
Source File: SessionTest.java    From openerp-java-api with Apache License 2.0 5 votes vote down vote up
private static void mockValidLogin() {
	mockServer
			.when(request().withMethod("POST").withPath("/xmlrpc/2/common").withBody(new StringBody(
					"<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodCall><methodName>login</methodName><params><param><value>"
							+ MOCK_DATABASE_NAME + "</value></param><param><value>" + ADMIN
							+ "</value></param><param><value>" + ADMIN + "</value></param></params></methodCall>")))
			.respond(response().withStatusCode(200).withBody(
					"<?xml version='1.0'?>\n<methodResponse>\n<params>\n<param>\n<value><int>1</int></value>\n</param>\n</params>\n</methodResponse>\n"));
}
 
Example #9
Source File: SessionTest.java    From openerp-java-api with Apache License 2.0 5 votes vote down vote up
private static void mockGetContext() {
	mockServer
			.when(request().withMethod("POST").withPath("/xmlrpc/2/object").withBody(new StringBody(
					"<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodCall><methodName>execute</methodName><params><param><value>"
							+ MOCK_DATABASE_NAME
							+ "</value></param><param><value><i4>1</i4></value></param><param><value>" + ADMIN
							+ "</value></param><param><value>res.users</value></param><param><value>context_get</value></param></params></methodCall>")))
			.respond(response().withStatusCode(200).withBody(
					"<?xml version='1.0'?>\n<methodResponse>\n<params>\n<param>\n<value><struct>\n<member>\n<name>lang</name>\n<value><string>en_US</string></value>\n</member>\n<member>\n<name>tz</name>\n<value><string>Europe/Brussels</string></value>\n</member>\n</struct></value>\n</param>\n</params>\n</methodResponse>\n"));
}
 
Example #10
Source File: SessionTest.java    From openerp-java-api with Apache License 2.0 5 votes vote down vote up
private static void mockLoginWrongUsername() {
	mockServer
			.when(request().withMethod("POST").withPath("/xmlrpc/2/common")
					.withBody(new StringBody(
							"<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodCall><methodName>login</methodName><params><param><value>"
									+ MOCK_DATABASE_NAME
									+ "</value></param><param><value>wrong_userName</value></param><param><value>"
									+ ADMIN + "</value></param></params></methodCall>")))
			.respond(response().withStatusCode(200).withBody(
					"<?xml version='1.0'?>\n<methodResponse>\n<params>\n<param>\n<value><boolean>0</boolean></value>\n</param>\n</params>\n</methodResponse>\n"));
}
 
Example #11
Source File: SessionTest.java    From openerp-java-api with Apache License 2.0 5 votes vote down vote up
private static void mockLoginWrongPassword() {
	mockServer
			.when(request().withMethod("POST").withPath("/xmlrpc/2/common")
					.withBody(new StringBody(
							"<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodCall><methodName>login</methodName><params><param><value>"
									+ MOCK_DATABASE_NAME + "</value></param><param><value>" + ADMIN
									+ "</value></param><param><value>wrong_password</value></param></params></methodCall>")))
			.respond(response().withStatusCode(200).withBody(
					"<?xml version='1.0'?>\n<methodResponse>\n<params>\n<param>\n<value><boolean>0</boolean></value>\n</param>\n</params>\n</methodResponse>\n"));
}
 
Example #12
Source File: SessionTest.java    From openerp-java-api with Apache License 2.0 5 votes vote down vote up
private static void mockLoginWrongDb() {
	mockServer
			.when(request().withMethod("POST").withPath("/xmlrpc/2/common")
					.withBody(new StringBody(
							"<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodCall><methodName>login</methodName><params><param><value>wrong_db</value></param><param><value>"
									+ ADMIN + "</value></param><param><value>" + ADMIN
									+ "</value></param></params></methodCall>")))
			.respond(response().withStatusCode(200).withBody(
					"<?xml version='1.0'?>\n<methodResponse>\n<fault>\n<value><struct>\n<member>\n<name>faultCode</name>\n<value><int>1</int></value>\n</member>\n<member>\n<name>faultString</name>\n<value><string>Traceback (most recent call last):\n  File \"/home/odoo/src/odoo/9.0/openerp/service/wsgi_server.py\", line 56, in xmlrpc_return\n    result = openerp.http.dispatch_rpc(service, method, params)\n  File \"/home/odoo/src/odoo/9.0/openerp/http.py\", line 114, in dispatch_rpc\n    result = dispatch(method, params)\n  File \"/home/odoo/src/odoo/9.0/openerp/service/common.py\", line 57, in dispatch\n    return g[exp_method_name](*params)\n  File \"/home/odoo/src/odoo/9.0/openerp/service/common.py\", line 23, in exp_login\n    res = security.login(db, login, password)\n  File \"/home/odoo/src/odoo/9.0/openerp/service/security.py\", line 8, in login\n    res_users = openerp.registry(db)['res.users']\n  File \"/home/odoo/src/odoo/9.0/openerp/__init__.py\", line 50, in registry\n    return modules.registry.RegistryManager.get(database_name)\n  File \"/home/odoo/src/odoo/9.0/openerp/modules/registry.py\", line 354, in get\n    update_module)\n  File \"/home/odoo/src/odoo/9.0/openerp/modules/registry.py\", line 371, in new\n    registry = Registry(db_name)\n  File \"/home/odoo/src/odoo/9.0/openerp/modules/registry.py\", line 63, in __init__\n    cr = self.cursor()\n  File \"/home/odoo/src/odoo/9.0/openerp/modules/registry.py\", line 278, in cursor\n    return self._db.cursor()\n  File \"/home/odoo/src/odoo/9.0/openerp/sql_db.py\", line 556, in cursor\n    return Cursor(self.__pool, self.dbname, self.dsn, serialized=serialized)\n  File \"/home/odoo/src/odoo/9.0/openerp/sql_db.py\", line 162, in __init__\n    self._cnx = pool.borrow(dsn)\n  File \"/home/odoo/src/odoo/9.0/openerp/sql_db.py\", line 445, in _locked\n    return fun(self, *args, **kwargs)\n  File \"/home/odoo/src/odoo/9.0/openerp/sql_db.py\", line 507, in borrow\n    result = psycopg2.connect(dsn=dsn, connection_factory=PsycoConnection)\n  File \"/usr/lib/python2.7/dist-packages/psycopg2/__init__.py\", line 179, in connect\n    connection_factory=connection_factory, async=async)\nOperationalError: FATAL:  database \"wrong_db\" does not exist\n\n</string></value>\n</member>\n</struct></value>\n</fault>\n</methodResponse>\n"));
}
 
Example #13
Source File: SessionTest.java    From openerp-java-api with Apache License 2.0 5 votes vote down vote up
private static void mockServerVersionResponse() {
	mockServer
			.when(request().withMethod("POST").withPath("/xmlrpc/2/db")
					.withBody(new StringBody(
							"<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodCall><methodName>server_version</methodName><params/></methodCall>")))
			.respond(response().withStatusCode(200).withBody(
					"<?xml version='1.0'?>\n<methodResponse>\n<params>\n<param>\n<value><string>9.0e</string></value>\n</param>\n</params>\n</methodResponse>\n"));
}
 
Example #14
Source File: HttpMockFacade.java    From cukes with Apache License 2.0 4 votes vote down vote up
public void setRequestBody(String body) {
    this.setRequestBody(new StringBody(body));
}