@Test public void removeConnection() throws Exception { ConnectionFactoryRegistry connectionFactoryLocator = new ConnectionFactoryRegistry(); ConnectionFactory<TestApi2> connectionFactory = new StubOAuth2ConnectionFactory("clientId", "clientSecret", THROW_EXCEPTION); connectionFactoryLocator.addConnectionFactory(connectionFactory); StubConnectionRepository connectionRepository = new StubConnectionRepository(); connectionRepository.addConnection( connectionFactory.createConnection( new ConnectionData( "oauth2Provider", "provider1User1", null, null, null, null, null, null, null))); connectionRepository.addConnection( connectionFactory.createConnection( new ConnectionData( "oauth2Provider", "provider1User2", null, null, null, null, null, null, null))); assertEquals(2, connectionRepository.findConnections("oauth2Provider").size()); ConnectController connectController = new ConnectController(connectionFactoryLocator, connectionRepository); List<DisconnectInterceptor<?>> interceptors = getDisconnectInterceptor(); connectController.setDisconnectInterceptors(interceptors); MockMvc mockMvc = standaloneSetup(connectController).build(); mockMvc .perform(delete("/connect/oauth2Provider/provider1User1")) .andExpect(redirectedUrl("/connect/oauth2Provider")); assertEquals(1, connectionRepository.findConnections("oauth2Provider").size()); assertFalse(((TestConnectInterceptor<?>) (interceptors.get(0))).preDisconnectInvoked); assertFalse(((TestConnectInterceptor<?>) (interceptors.get(0))).postDisconnectInvoked); assertNull(((TestConnectInterceptor<?>) (interceptors.get(0))).connectionFactory); assertTrue(((TestConnectInterceptor<?>) (interceptors.get(1))).preDisconnectInvoked); assertTrue(((TestConnectInterceptor<?>) (interceptors.get(1))).postDisconnectInvoked); assertSame( connectionFactory, ((TestConnectInterceptor<?>) (interceptors.get(1))).connectionFactory); }
@Test public void testTwoInclude() throws Exception { HttpGet httpGet = new HttpGet( "http://localhost:" + ourPort + "/Patient?name=Hello&_include=foo&_include=bar&_pretty=true"); HttpResponse status = ourClient.execute(httpGet); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info(responseContent); assertEquals(200, status.getStatusLine().getStatusCode()); Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); assertEquals(1, bundle.size()); Patient p = bundle.getResources(Patient.class).get(0); assertEquals(2, p.getName().size()); assertEquals("Hello", p.getId().getIdPart()); Set<String> values = new HashSet<String>(); values.add(p.getName().get(0).getFamilyFirstRep().getValue()); values.add(p.getName().get(1).getFamilyFirstRep().getValue()); assertThat(values, containsInAnyOrder("foo", "bar")); }
@Test public void pathSegments() throws URISyntaxException { UriComponentsBuilder builder = UriComponentsBuilder.newInstance(); UriComponents result = builder.pathSegment("foo").pathSegment("bar").build(); assertEquals("/foo/bar", result.getPath()); assertEquals(Arrays.asList("foo", "bar"), result.getPathSegments()); }
@Test public void testClone() throws URISyntaxException { UriComponentsBuilder builder1 = UriComponentsBuilder.newInstance(); builder1 .scheme("http") .host("e1.com") .path("/p1") .pathSegment("ps1") .queryParam("q1") .fragment("f1"); UriComponentsBuilder builder2 = (UriComponentsBuilder) builder1.clone(); builder2 .scheme("https") .host("e2.com") .path("p2") .pathSegment("ps2") .queryParam("q2") .fragment("f2"); UriComponents result1 = builder1.build(); assertEquals("http", result1.getScheme()); assertEquals("e1.com", result1.getHost()); assertEquals("/p1/ps1", result1.getPath()); assertEquals("q1", result1.getQuery()); assertEquals("f1", result1.getFragment()); UriComponents result2 = builder2.build(); assertEquals("https", result2.getScheme()); assertEquals("e2.com", result2.getHost()); assertEquals("/p1/ps1/p2/ps2", result2.getPath()); assertEquals("q1&q2", result2.getQuery()); assertEquals("f2", result2.getFragment()); }
@Test // SPR-10779 public void fromHttpUrlStringCaseInsesitiveScheme() { assertEquals( "http", UriComponentsBuilder.fromHttpUrl("HTTP://www.google.com").build().getScheme()); assertEquals( "https", UriComponentsBuilder.fromHttpUrl("HTTPS://www.google.com").build().getScheme()); }
@Test public void oauth2Callback() throws Exception { ConnectionFactoryRegistry connectionFactoryLocator = new ConnectionFactoryRegistry(); ConnectionFactory<TestApi2> connectionFactory = new StubOAuth2ConnectionFactory("clientId", "clientSecret"); connectionFactoryLocator.addConnectionFactory(connectionFactory); StubConnectionRepository connectionRepository = new StubConnectionRepository(); ConnectController connectController = new ConnectController(connectionFactoryLocator, connectionRepository); List<ConnectInterceptor<?>> interceptors = getConnectInterceptor(); connectController.setConnectInterceptors(interceptors); connectController.afterPropertiesSet(); MockMvc mockMvc = standaloneSetup(connectController).build(); assertEquals(0, connectionRepository.findConnections("oauth2Provider").size()); mockMvc .perform(get("/connect/oauth2Provider").param("code", "oauth2Code")) .andExpect(redirectedUrl("/connect/oauth2Provider")); List<Connection<?>> connections = connectionRepository.findConnections("oauth2Provider"); assertEquals(1, connections.size()); assertEquals("oauth2Provider", connections.get(0).getKey().getProviderId()); // Check for postConnect() only. The preConnect() is only invoked during the initial portion of // the flow assertFalse(((TestConnectInterceptor<?>) (interceptors.get(0))).postConnectInvoked); TestConnectInterceptor<?> testInterceptor2 = (TestConnectInterceptor<?>) (interceptors.get(1)); assertTrue(testInterceptor2.postConnectInvoked); }
@When("^I start the program$") public void I_start_the_program() throws InterruptedException { programWaitLock = new Semaphore(programWaitLockPermits); addScriptEndCallbacks(); Solo solo = (Solo) Cucumber.get(Cucumber.KEY_SOLO); assertEquals( "I am in the wrong Activity.", MainMenuActivity.class, solo.getCurrentActivity().getClass()); solo.clickOnView(solo.getView(org.catrobat.catroid.R.id.main_menu_button_continue)); solo.waitForActivity(ProjectActivity.class.getSimpleName(), 3000); assertEquals( "I am in the wrong Activity.", ProjectActivity.class, solo.getCurrentActivity().getClass()); solo.clickOnView(solo.getView(org.catrobat.catroid.R.id.button_play)); solo.waitForActivity(StageActivity.class.getSimpleName(), 3000); assertEquals( "I am in the wrong Activity.", StageActivity.class, solo.getCurrentActivity().getClass()); synchronized (programStartWaitLock) { if (!programHasStarted) { programStartWaitLock.wait(10000); } } }
@org.junit.Test public void testExcludes() { assertSame(test, test.exclude(TEST_PATTERN_1, TEST_PATTERN_2)); assertEquals(toLinkedSet(TEST_PATTERN_1, TEST_PATTERN_2), test.getExcludes()); test.exclude(TEST_PATTERN_3); assertEquals(toLinkedSet(TEST_PATTERN_1, TEST_PATTERN_2, TEST_PATTERN_3), test.getExcludes()); }
@Test public void testRemoveAndWriteAllReentrance() { EmbeddedChannel channel = new EmbeddedChannel(new ChannelInboundHandlerAdapter()); final PendingWriteQueue queue = new PendingWriteQueue(channel.pipeline().firstContext()); ChannelPromise promise = channel.newPromise(); promise.addListener( new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { queue.removeAndWriteAll(); } }); queue.add(1L, promise); ChannelPromise promise2 = channel.newPromise(); queue.add(2L, promise2); queue.removeAndWriteAll(); channel.flush(); assertTrue(promise.isSuccess()); assertTrue(promise2.isSuccess()); assertTrue(channel.finish()); assertEquals(1L, channel.readOutbound()); assertEquals(2L, channel.readOutbound()); assertNull(channel.readOutbound()); assertNull(channel.readInbound()); }
public void testOnCloseCallback() throws IOException { final ShardId shardId = new ShardId( new Index(randomRealisticUnicodeOfCodepointLengthBetween(1, 10)), randomIntBetween(0, 100)); DirectoryService directoryService = new LuceneManagedDirectoryService(random()); final AtomicInteger count = new AtomicInteger(0); final ShardLock lock = new DummyShardLock(shardId); Store store = new Store( shardId, ImmutableSettings.EMPTY, directoryService, randomDistributor(directoryService), lock, new Store.OnClose() { @Override public void handle(ShardLock theLock) { assertEquals(shardId, theLock.getShardId()); assertEquals(lock, theLock); count.incrementAndGet(); } }); assertEquals(count.get(), 0); final int iters = randomIntBetween(1, 10); for (int i = 0; i < iters; i++) { store.close(); } assertEquals(count.get(), 1); }
@Test public void cornerSpr8937AndSpr12582() throws IntrospectionException { @SuppressWarnings("unused") class A { public void setAddress(String addr) {} public void setAddress(int index, String addr) {} public String getAddress(int index) { return null; } } // Baseline: BeanInfo bi = Introspector.getBeanInfo(A.class); boolean hasReadMethod = hasReadMethodForProperty(bi, "address"); boolean hasWriteMethod = hasWriteMethodForProperty(bi, "address"); boolean hasIndexedReadMethod = hasIndexedReadMethodForProperty(bi, "address"); boolean hasIndexedWriteMethod = hasIndexedWriteMethodForProperty(bi, "address"); // ExtendedBeanInfo needs to behave exactly like BeanInfo... BeanInfo ebi = new ExtendedBeanInfo(bi); assertEquals(hasReadMethod, hasReadMethodForProperty(ebi, "address")); assertEquals(hasWriteMethod, hasWriteMethodForProperty(ebi, "address")); assertEquals(hasIndexedReadMethod, hasIndexedReadMethodForProperty(ebi, "address")); assertEquals(hasIndexedWriteMethod, hasIndexedWriteMethodForProperty(ebi, "address")); }
@Test public void testDataSourceRepo() throws SQLException, RepositoryException { DataSourceWorkflowRepository repo = new DataSourceWorkflowRepository(ds); // test id 1 WorkflowCondition wc = repo.getWorkflowConditionById("1"); assertEquals(wc.getConditionName(), "CheckCond"); WorkflowConditionInstance condInst = GenericWorkflowObjectFactory.getConditionObjectFromClassName( wc.getConditionInstanceClassName()); Metadata m = new Metadata(); m.addMetadata("Met1", "Val1"); m.addMetadata("Met2", "Val2"); m.addMetadata("Met3", "Val3"); assertTrue(condInst.evaluate(m, wc.getTaskConfig())); // test id 2 wc = repo.getWorkflowConditionById("2"); assertEquals(wc.getConditionName(), "FalseCond"); condInst = GenericWorkflowObjectFactory.getConditionObjectFromClassName( wc.getConditionInstanceClassName()); assertFalse(condInst.evaluate(m, wc.getTaskConfig())); // test id 3 wc = repo.getWorkflowConditionById("3"); assertEquals(wc.getConditionName(), "TrueCond"); condInst = GenericWorkflowObjectFactory.getConditionObjectFromClassName( wc.getConditionInstanceClassName()); assertTrue(condInst.evaluate(m, wc.getTaskConfig())); }
@Test public void pathThenPathSegments() { UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/foo/bar").pathSegment("ba/z"); UriComponents result = builder.build().encode(); assertEquals("/foo/bar/ba%2Fz", result.getPath()); assertEquals(Arrays.asList("foo", "bar", "ba%2Fz"), result.getPathSegments()); }
@Test // SPR-9832 public void fromUriStringQueryParamWithReservedCharInValue() throws URISyntaxException { String uri = "http://www.google.com/ig/calculator?q=1USD=?EUR"; UriComponents result = UriComponentsBuilder.fromUriString(uri).build(); assertEquals("q=1USD=?EUR", result.getQuery()); assertEquals("1USD=?EUR", result.getQueryParams().getFirst("q")); }
@Test public void expand() { UriComponents uriComponents = UriComponentsBuilder.fromUriString("http://example.com").path("/{foo} {bar}").build(); uriComponents = uriComponents.expand("1 2", "3 4"); assertEquals("/1 2 3 4", uriComponents.getPath()); assertEquals("http://example.com/1 2 3 4", uriComponents.toUriString()); }
@Test public void pathSegmentsThenPath() { UriComponentsBuilder builder = UriComponentsBuilder.newInstance().pathSegment("foo").path("/"); UriComponents result = builder.build(); assertEquals("/foo/", result.getPath()); assertEquals(Collections.singletonList("foo"), result.getPathSegments()); }
@Test public void location_coordinates_can_be_set() { Location l = createLocation(); l.setX(5); l.setY(10); assertEquals(5, l.x()); assertEquals(10, l.y()); }
@Test public void testUnsupportedParsing() throws Exception { Map value = new ObjectMapper().readValue(getClass().getResourceAsStream("attachment.json"), Map.class); Field fl = Field.parseField(value); assertEquals("person", fl.name()); assertEquals(0, fl.properties().length); }
public void send(String message, int count) { assertEquals(this.count, count); this.count++; if (message.equals("stop")) { assertEquals(4, this.count); stopReceived.countDown(); } }
@Test @SuppressWarnings("rawtypes") public void discoversBoundTypeForNested() { TypeInformation<AnotherGenericType> information = ClassTypeInformation.from(AnotherGenericType.class); assertEquals(GenericTypeWithBound.class, information.getProperty("nested").getType()); assertEquals(Person.class, information.getProperty("nested.person").getType()); }
@Test public void copyToUriComponentsBuilder() { UriComponents source = UriComponentsBuilder.fromPath("/foo/bar").pathSegment("ba/z").build(); UriComponentsBuilder targetBuilder = UriComponentsBuilder.newInstance(); source.copyToUriComponentsBuilder(targetBuilder); UriComponents result = targetBuilder.build().encode(); assertEquals("/foo/bar/ba%2Fz", result.getPath()); assertEquals(Arrays.asList("foo", "bar", "ba%2Fz"), result.getPathSegments()); }
@Test public void findMergedAnnotationWithAttributeAliasesInTargetAnnotation() { Class<?> element = AliasedTransactionalComponentClass.class; AliasedTransactional annotation = findMergedAnnotation(element, AliasedTransactional.class); assertNotNull("@AliasedTransactional on " + element, annotation); assertEquals("TX value via synthesized annotation.", "aliasForQualifier", annotation.value()); assertEquals( "TX qualifier via synthesized annotation.", "aliasForQualifier", annotation.qualifier()); }
@Test public void executesLikeAndOrderByCorrectly() throws Exception { flushTestUsers(); List<User> result = userDao.findByLastnameLikeOrderByFirstnameDesc("%r%"); assertEquals(firstUser, result.get(0)); assertEquals(secondUser, result.get(1)); }
@Test public void javaxAnnotationTypeViaFindMergedAnnotation() throws Exception { assertEquals( ResourceHolder.class.getAnnotation(Resource.class), findMergedAnnotation(ResourceHolder.class, Resource.class)); assertEquals( SpringAppConfigClass.class.getAnnotation(Resource.class), findMergedAnnotation(SpringAppConfigClass.class, Resource.class)); }
public void assertCanExecute() { assertNull(getExecutable()); assertEquals(getJavaHome(), Jvm.current().getJavaHome()); String defaultEncoding = getImplicitJvmSystemProperties().get("file.encoding"); if (defaultEncoding != null) { assertEquals(Charset.forName(defaultEncoding), Charset.defaultCharset()); } assertFalse(isRequireGradleHome()); }
@Test // SPR-11970 public void fromUriStringNoPathWithReservedCharInQuery() { UriComponents result = UriComponentsBuilder.fromUriString("http://example.com?foo=bar@baz").build(); assertTrue(StringUtils.isEmpty(result.getUserInfo())); assertEquals("example.com", result.getHost()); assertTrue(result.getQueryParams().containsKey("foo")); assertEquals("bar@baz", result.getQueryParams().getFirst("foo")); }
@Test public void pathSegmentsSomeEmpty() { UriComponentsBuilder builder = UriComponentsBuilder.newInstance().pathSegment("", "foo", "", "bar"); UriComponents result = builder.build(); assertEquals("/foo/bar", result.getPath()); assertEquals(Arrays.asList("foo", "bar"), result.getPathSegments()); }
@Test public void testCompletionParsing() throws Exception { Map value = new ObjectMapper().readValue(getClass().getResourceAsStream("completion.json"), Map.class); Field fl = Field.parseField(value); assertEquals("song", fl.name()); Field[] props = fl.properties(); assertEquals(1, props.length); assertEquals("name", props[0].name()); }
@Test public void checkoutOptionRemoval() { Session session = Session.createTestSession(); session.handleInput(Constants.checkoutBookCommand + " Book 1"); session.handleInput(Constants.listBooksCommand); String[] lines = session.history(-2).split("\n"); assertEquals( String.format(Constants.bookFormatString, "Book 2", "Author 2", 1976, "1"), lines[1]); assertEquals(2, lines.length); }
@Test public void emptyQueryParam() throws URISyntaxException { UriComponentsBuilder builder = UriComponentsBuilder.newInstance(); UriComponents result = builder.queryParam("baz").build(); assertEquals("baz", result.getQuery()); MultiValueMap<String, String> expectedQueryParams = new LinkedMultiValueMap<>(2); expectedQueryParams.add("baz", null); assertEquals(expectedQueryParams, result.getQueryParams()); }