@Test public void write_protobuf() throws Exception { TestRequest request = new TestRequest(); request.setMediaType(MediaTypes.PROTOBUF); DumbResponse response = new DumbResponse(); Issues.Issue msg = Issues.Issue.newBuilder().setKey("I1").build(); WsUtils.writeProtobuf(msg, request, response); assertThat(response.stream().mediaType()).isEqualTo(MediaTypes.PROTOBUF); assertThat(Issues.Issue.parseFrom(response.getFlushedOutput()).getKey()).isEqualTo("I1"); }
public void testTransferError() throws Exception { File simpleRepo = getTestData("simple repository", "testData/artifactRepo/transferTestRepo"); IArtifactRepository source = null; IArtifactRepository target = null; try { source = getArtifactRepositoryManager() .loadRepository(simpleRepo.toURI(), new NullProgressMonitor()); target = createArtifactRepository(new File(getTempFolder(), getName()).toURI(), null); } catch (ProvisionException e) { fail("failing setting up the tests", e); } IArtifactDescriptor sourceDescriptor = getArtifactKeyFor( source, "osgi.bundle", "missingFromFileSystem", Version.createOSGi(1, 0, 0))[0]; SimpleArtifactDescriptor targetDescriptor = new SimpleArtifactDescriptor(sourceDescriptor); targetDescriptor.setRepositoryProperty("artifact.folder", "true"); class TestRequest extends MirrorRequest { public TestRequest( IArtifactKey key, IArtifactRepository targetRepository, Map<String, String> targetDescriptorProperties, Map<String, String> targetRepositoryProperties) { super( key, targetRepository, targetDescriptorProperties, targetRepositoryProperties, getTransport()); } public void setSource(IArtifactRepository source) { super.setSourceRepository(source); } } TestRequest request = new TestRequest( new ArtifactKey("osgi.bundle", "missingFromFileSystem", Version.createOSGi(1, 0, 0)), target, null, null); request.setSource(source); IStatus s = transferSingle(request, targetDescriptor, sourceDescriptor, new NullProgressMonitor()); assertTrue(s.toString(), s.getException().getClass() == FileNotFoundException.class); }
@Test(groups = "require-test-server-running") public void testEndpointVoidResult() { TestEndpoint te = applicationContext.getBean(TestEndpoint.class); TestRequest tr1 = new TestRequest(); tr1.setStringField("string"); tr1.setCreated(new Date()); tr1.setRequestId(System.currentTimeMillis() + ":"); tr1.setRequestSource("src"); tr1.setSessionId("session" + System.currentTimeMillis()); te.testVoidResult(tr1); }
@Test(groups = "require-test-server-running") public void testEndpointException() { TestEndpoint te = applicationContext.getBean(TestEndpoint.class); TestRequest tr1 = new TestRequest(); tr1.setStringField("string"); tr1.setCreated(new Date()); tr1.setRequestId(System.currentTimeMillis() + ":"); tr1.setRequestSource("src"); tr1.setSessionId("session" + System.currentTimeMillis()); TestResponse tr = te.testException(tr1); assertEquals(EndpointResponseStatus.ERROR, tr.getStatus()); }
@Test public void compareTo() { int sequence = 0; TestRequest low = new TestRequest(Priority.LOW); low.setSequence(sequence++); TestRequest low2 = new TestRequest(Priority.LOW); low2.setSequence(sequence++); TestRequest high = new TestRequest(Priority.HIGH); high.setSequence(sequence++); TestRequest immediate = new TestRequest(Priority.IMMEDIATE); immediate.setSequence(sequence++); // "Low" should sort higher because it's really processing order. assertTrue(low.compareTo(high) > 0); assertTrue(high.compareTo(low) < 0); assertTrue(low.compareTo(low2) < 0); assertTrue(low.compareTo(immediate) > 0); assertTrue(immediate.compareTo(high) < 0); }