use of com.cloudant.http.internal.interceptors.UserAgentInterceptor in project java-cloudant by cloudant.
the class CloudantClientTests method testUserAgentHeaderStringFromFile.
@Test
public void testUserAgentHeaderStringFromFile() throws Exception {
// This doesn't read the a properties file, since the tests do not run from the published
// jars.
// Point to the built classes, it's a bit awkward but we need to load the class cleanly
File f = new File("../cloudant-http/build/classes/main/");
String userAgentHeader = new UserAgentInterceptor(new URLClassLoader(new URL[] { f.toURI().toURL() }) {
@Override
public InputStream getResourceAsStream(String name) {
if (name.equals("META-INF/com.cloudant.client.properties")) {
try {
return new ByteArrayInputStream(("user.agent.name=java-cloudant\nuser" + ".agent.version=1.6.1").getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
return super.getResourceAsStream(name);
}
}, "META-INF/com.cloudant.client.properties").getUserAgent();
assertTrue(userAgentHeader.matches(userAgentRegex), "The value of the User-Agent header: " + "" + userAgentHeader + " should match the " + "format: " + userAgentFormat);
}
use of com.cloudant.http.internal.interceptors.UserAgentInterceptor in project java-cloudant by cloudant.
the class CloudantClientTests method testUserAgentHeaderString.
/**
* Assert that the User-Agent header is of the expected form.
*/
@Test
public void testUserAgentHeaderString() throws Exception {
// This doesn't read the a properties file, since the tests do not run from the published
// jars.
String userAgentHeader = new UserAgentInterceptor(UserAgentInterceptor.class.getClassLoader(), "META-INF/com.cloudant.client.properties").getUserAgent();
assertTrue(userAgentHeader.matches(userAgentUnknownRegex), "The value of the User-Agent " + "header: " + userAgentHeader + " should match the " + "format: " + userAgentFormat);
}
Aggregations