@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 getsFedOptionDescriptorsForRecognizedOptions() {
   assertEquals(1, captured.size());
   Map.Entry<String, ? extends OptionDescriptor> only = captured.entrySet().iterator().next();
   assertEquals("b", only.getKey());
   OptionDescriptor descriptor = only.getValue();
   assertThat(descriptor.options(), hasSameContentsAs(asList("b")));
   assertEquals("boo", descriptor.description());
   assertFalse(descriptor.acceptsArguments());
   assertFalse(descriptor.requiresArgument());
   assertEquals("", descriptor.argumentDescription());
   assertEquals("", descriptor.argumentTypeIndicator());
   assertEquals(Collections.<Object>emptyList(), descriptor.defaultValues());
 }
  @Test
  public void supportsPosixlyCorrectBehavior() {
    OptionParser parser = new OptionParser("i:j::k");
    String[] arguments = {
      "-ibar", "-i", "junk", "xyz", "-jixnay", "foo", "-k", "blah", "--", "bah"
    };

    OptionSet options = parser.parse(arguments);

    assertTrue(options.has("i"));
    assertTrue(options.has("j"));
    assertTrue(options.has("k"));
    assertEquals(asList("bar", "junk"), options.valuesOf("i"));
    assertEquals(singletonList("ixnay"), options.valuesOf("j"));
    assertEquals(asList("xyz", "foo", "blah", "bah"), options.nonOptionArguments());

    parser.posixlyCorrect(true);
    options = parser.parse(arguments);

    assertTrue(options.has("i"));
    assertFalse(options.has("j"));
    assertFalse(options.has("k"));
    assertEquals(asList("bar", "junk"), options.valuesOf("i"));
    assertEquals(emptyList(), options.valuesOf("j"));
    assertEquals(
        asList("xyz", "-jixnay", "foo", "-k", "blah", "--", "bah"), options.nonOptionArguments());
  }
  @Test
  public void all() {
    final List<String> values = asList("a", "b", "a", "c", "a", "d", "e");
    assertTrue(Algorithms.all(values, Conditions.gte("a")));
    assertTrue(Algorithms.all(values, Conditions.lt("z")));
    assertTrue(Algorithms.all(values, Conditions.lte("e")));

    assertFalse(Algorithms.all(values, Conditions.gt("b")));
    assertFalse(Algorithms.all(values, Conditions.eq("a")));
    assertFalse(Algorithms.all(values, Conditions.eq("f")));
  }
 @Test
 public void connect_OAuth1Provider() throws Exception {
   ConnectionFactoryRegistry connectionFactoryLocator = new ConnectionFactoryRegistry();
   ConnectionFactory<TestApi1> connectionFactory =
       new StubOAuth1ConnectionFactory("clientId", "clientSecret");
   connectionFactoryLocator.addConnectionFactory(connectionFactory);
   ConnectController connectController = new ConnectController(connectionFactoryLocator, null);
   List<ConnectInterceptor<?>> interceptors = getConnectInterceptor();
   connectController.setConnectInterceptors(interceptors);
   connectController.afterPropertiesSet();
   MockMvc mockMvc = standaloneSetup(connectController).build();
   mockMvc
       .perform(post("/connect/oauth1Provider"))
       .andExpect(
           redirectedUrl("https://someprovider.com/oauth/authorize?oauth_token=requestToken"))
       .andExpect(
           request()
               .sessionAttribute(
                   "oauthToken",
                   samePropertyValuesAs(new OAuthToken("requestToken", "requestTokenSecret"))));
   // Check for preConnect() only. The postConnect() won't be invoked until after callback
   TestConnectInterceptor<?> textInterceptor1 = (TestConnectInterceptor<?>) (interceptors.get(0));
   assertTrue(textInterceptor1.preConnectInvoked);
   assertEquals("oauth1Provider", textInterceptor1.connectionFactory.getProviderId());
   assertFalse(((TestConnectInterceptor<?>) (interceptors.get(1))).preConnectInvoked);
 }
 @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);
 }
 @Test
 public void one() {
   final List<String> values = asList("a", "b", "a", "c", "a", "d", "e");
   assertTrue(Algorithms.one(values, Conditions.eq("c")));
   assertTrue(Algorithms.one(values, Conditions.eq("a")));
   assertTrue(Algorithms.one(values, Conditions.eq("e")));
   assertFalse(Algorithms.one(values, Conditions.eq("f")));
 }
 @Test
 public void getMergedAnnotationAttributesFromInterfaceImplementedBySuperclass() {
   Class<?> element = ConcreteClassWithInheritedAnnotation.class;
   String name = TX_NAME;
   AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name);
   assertNull(
       "Should not find @Transactional on ConcreteClassWithInheritedAnnotation", attributes);
   // Verify contracts between utility methods:
   assertFalse(isAnnotated(element, name));
 }
 @Test
 public void hasMetaAnnotationTypesOnClassWithMetaDepth2() {
   assertTrue(hasMetaAnnotationTypes(ComposedTransactionalComponentClass.class, TX_NAME));
   assertTrue(
       hasMetaAnnotationTypes(
           ComposedTransactionalComponentClass.class, Component.class.getName()));
   assertFalse(
       hasMetaAnnotationTypes(
           ComposedTransactionalComponentClass.class,
           ComposedTransactionalComponent.class.getName()));
 }
 @Test
 public void
     getMergedAnnotationAttributesFavorsInheritedAnnotationsOverMoreLocallyDeclaredComposedAnnotations() {
   Class<?> element = SubSubClassWithInheritedAnnotation.class;
   String name = TX_NAME;
   AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name);
   assertNotNull(
       "AnnotationAttributes for @Transactional on SubSubClassWithInheritedAnnotation",
       attributes);
   // Verify contracts between utility methods:
   assertTrue(isAnnotated(element, name));
   assertFalse(
       "readOnly flag for SubSubClassWithInheritedAnnotation.", attributes.getBoolean("readOnly"));
 }
  @Test
  public void shouldLookForClassesInTargetDirectories() throws Exception {
    newDir = new File("tempClassDir");
    List<File> buildPaths = asList(newDir);
    ClasspathProvider classpath =
        new StandaloneClasspath(
            buildPaths,
            FakeEnvironments.systemClasspath() + pathSeparator + newDir.getAbsolutePath());

    String classname = "org.fakeco.Foobar";
    createClass(classname);

    builder = new JavaClassBuilder(classpath);
    JavaClass javaClass = builder.createClass(classname);
    assertEquals(classname, javaClass.getName());
    assertFalse(javaClass.isATest());
  }
 @Test
 public void connect_OAuth2Provider() throws Exception {
   ConnectionFactoryRegistry connectionFactoryLocator = new ConnectionFactoryRegistry();
   ConnectionFactory<TestApi2> connectionFactory =
       new StubOAuth2ConnectionFactory("clientId", "clientSecret");
   connectionFactoryLocator.addConnectionFactory(connectionFactory);
   ConnectController connectController = new ConnectController(connectionFactoryLocator, null);
   List<ConnectInterceptor<?>> interceptors = getConnectInterceptor();
   connectController.setConnectInterceptors(interceptors);
   MockMvc mockMvc = standaloneSetup(connectController).build();
   mockMvc.perform(post("/connect/oauth2Provider")).andExpect(redirectedUrl(OAUTH2_AUTHORIZE_URL));
   // Check for preConnect() only. The postConnect() won't be invoked until after callback
   assertFalse(((TestConnectInterceptor<?>) (interceptors.get(0))).preConnectInvoked);
   TestConnectInterceptor<?> testInterceptor2 = (TestConnectInterceptor<?>) (interceptors.get(1));
   assertTrue(testInterceptor2.preConnectInvoked);
   assertEquals("oauth2Provider", testInterceptor2.connectionFactory.getProviderId());
 }
 @Test
 public void hasMetaAnnotationTypesOnClassWithMetaDepth0() {
   assertFalse(
       hasMetaAnnotationTypes(
           TransactionalComponentClass.class, TransactionalComponent.class.getName()));
 }
Example #14
0
 public void assertTestPassed(String name) {
   assertTestRun(name);
   assertFalse(name + " failed! Expected to pass", testCaseEvents.get(name).failed());
 }
 @Test
 public void isAnnotatedOnNonAnnotatedClass() {
   assertFalse(isAnnotated(NonAnnotatedClass.class, TX_NAME));
 }
 @Test
 public void isAnnotatedOnSubclassWithMetaDepth0() {
   assertFalse(
       "isAnnotated() does not search the class hierarchy.",
       isAnnotated(SubTransactionalComponentClass.class, TransactionalComponent.class.getName()));
 }
 @Test
 public void hasMetaAnnotationTypesOnNonAnnotatedClass() {
   assertFalse(hasMetaAnnotationTypes(NonAnnotatedClass.class, TX_NAME));
 }
 private <T> void doNotMatch(InstanceFilter<T> filter, T candidate) {
   assertFalse("filter '" + filter + "' should not match " + candidate, filter.match(candidate));
 }