Example usage for junit.framework Assert assertNotNull

List of usage examples for junit.framework Assert assertNotNull

Introduction

In this page you can find the example usage for junit.framework Assert assertNotNull.

Prototype

static public void assertNotNull(String message, Object object) 

Source Link

Document

Asserts that an object isn't null.

Usage

From source file:org.xdi.oxauth.dev.TestSessionWorkflow.java

@Parameters({ "userId", "userSecret", "clientId", "clientSecret", "redirectUri" })
@Test/*from   w ww .j  av  a  2  s.  c  o m*/
public void test(final String userId, final String userSecret, final String clientId, final String clientSecret,
        final String redirectUri) throws Exception {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    try {
        CookieStore cookieStore = new BasicCookieStore();
        httpClient.setCookieStore(cookieStore);
        ClientExecutor clientExecutor = new ApacheHttpClient4Executor(httpClient);

        ////////////////////////////////////////////////
        //             TV side. Code 1                //
        ////////////////////////////////////////////////

        AuthorizationRequest authorizationRequest1 = new AuthorizationRequest(Arrays.asList(ResponseType.CODE),
                clientId, Arrays.asList("openid", "profile", "email"), redirectUri, null);

        authorizationRequest1.setAuthUsername(userId);
        authorizationRequest1.setAuthPassword(userSecret);
        authorizationRequest1.getPrompts().add(Prompt.NONE);
        authorizationRequest1.setState("af0ifjsldkj");
        authorizationRequest1.setRequestSessionId(true);

        AuthorizeClient authorizeClient1 = new AuthorizeClient(authorizationEndpoint);
        authorizeClient1.setRequest(authorizationRequest1);
        AuthorizationResponse authorizationResponse1 = authorizeClient1.exec(clientExecutor);

        //        showClient(authorizeClient1, cookieStore);

        String code1 = authorizationResponse1.getCode();
        String sessionId = authorizationResponse1.getSessionId();
        Assert.assertNotNull("code1 is null", code1);
        Assert.assertNotNull("sessionId is null", sessionId);

        // TV sends the code to the Backend
        // We don't use httpClient and cookieStore during this call

        ////////////////////////////////////////////////
        //             Backend  1 side. Code 1        //
        ////////////////////////////////////////////////

        // Get the access token
        TokenClient tokenClient1 = new TokenClient(tokenEndpoint);
        TokenResponse tokenResponse1 = tokenClient1.execAuthorizationCode(code1, redirectUri, clientId,
                clientSecret);

        String accessToken1 = tokenResponse1.getAccessToken();
        Assert.assertNotNull("accessToken1 is null", accessToken1);

        // Get the user's claims
        UserInfoClient userInfoClient1 = new UserInfoClient(userInfoEndpoint);
        UserInfoResponse userInfoResponse1 = userInfoClient1.execUserInfo(accessToken1);

        Assert.assertTrue("userInfoResponse1.getStatus() is not 200", userInfoResponse1.getStatus() == 200);
        //        System.out.println(userInfoResponse1.getEntity());

        ////////////////////////////////////////////////
        //             TV side. Code 2                //
        ////////////////////////////////////////////////

        AuthorizationRequest authorizationRequest2 = new AuthorizationRequest(Arrays.asList(ResponseType.CODE),
                clientId, Arrays.asList("openid", "profile", "email"), redirectUri, null);

        authorizationRequest2.getPrompts().add(Prompt.NONE);
        authorizationRequest2.setState("af0ifjsldkj");
        authorizationRequest2.setSessionId(sessionId);

        AuthorizeClient authorizeClient2 = new AuthorizeClient(authorizationEndpoint);
        authorizeClient2.setRequest(authorizationRequest2);
        AuthorizationResponse authorizationResponse2 = authorizeClient2.exec(clientExecutor);

        //        showClient(authorizeClient2, cookieStore);

        String code2 = authorizationResponse2.getCode();
        Assert.assertNotNull("code2 is null", code2);

        // TV sends the code to the Backend
        // We don't use httpClient and cookieStore during this call

        ////////////////////////////////////////////////
        //             Backend  2 side. Code 2        //
        ////////////////////////////////////////////////

        // Get the access token
        TokenClient tokenClient2 = new TokenClient(tokenEndpoint);
        TokenResponse tokenResponse2 = tokenClient2.execAuthorizationCode(code2, redirectUri, clientId,
                clientSecret);

        String accessToken2 = tokenResponse2.getAccessToken();
        Assert.assertNotNull("accessToken2 is null", accessToken2);

        // Get the user's claims
        UserInfoClient userInfoClient2 = new UserInfoClient(userInfoEndpoint);
        UserInfoResponse userInfoResponse2 = userInfoClient2.execUserInfo(accessToken2);

        Assert.assertTrue("userInfoResponse1.getStatus() is not 200", userInfoResponse2.getStatus() == 200);
        //        System.out.println(userInfoResponse2.getEntity());
    } finally {
        if (httpClient != null) {
            httpClient.getConnectionManager().shutdown();
        }
    }
}

From source file:com.vmware.identity.idm.server.LocalOsIdentityProviderTest.java

@Test
public void TestUsers() throws Exception {
    for (UserInfo userInfo : _users.values()) {
        // ---------------------
        // findUser
        // ---------------------
        PersonUser user = localOsProvider.findUser(new PrincipalId(userInfo.getName(), domainName));
        Assert.assertNotNull(String.format("User '%s' should exist.", userInfo.getName()), user);
        validateUser(user, userInfo);/*from w  ww .ja v  a2s  . co  m*/

        // ---------------------
        // IsActive
        // ---------------------
        boolean isActive = SystemUtils.IS_OS_LINUX ? true : !userInfo.isDisabled();
        Assert.assertEquals(isActive,
                localOsProvider.IsActive(new PrincipalId(userInfo.getName(), domainName)));

        // ---------------------
        // getAttributes
        // ---------------------
        Collection<AttributeValuePair> attributes = localOsProvider
                .getAttributes(new PrincipalId(userInfo.getName(), domainName), getAttributes());

        Assert.assertNotNull(
                String.format("Should be able to retrieve attributes for User '%s'.", userInfo.getName()),
                attributes);

        for (AttributeValuePair attr : attributes) {
            Assert.assertNotNull(attr);
            Assert.assertNotNull(attr.getAttrDefinition());
            // new sids attributes comes without the friendly name.
            // Assert.assertNotNull( attr.getAttrDefinition().getFriendlyName() );

            if (GROUPS_FRIENDLY_NAME.equalsIgnoreCase(attr.getAttrDefinition().getFriendlyName())) {
                Set<GroupInfo> groups = _usersToGroups.get(userInfo.getName());
                if (groups != null && groups.isEmpty() == false) {
                    Assert.assertNotNull(attr.getValues());
                    Assert.assertTrue(groups.size() <= attr.getValues().size());
                    HashSet<String> attrGroups = new HashSet<String>();
                    for (String attributeValue : attr.getValues()) {
                        Assert.assertNotNull(attributeValue);
                        Assert.assertTrue(attributeValue.startsWith(domainName)
                                || (providerHasAlias() && attributeValue.startsWith(domainAlias)));
                        Assert.assertTrue(attributeValue.contains("\\"));

                        String groupName = attributeValue;

                        Assert.assertFalse(groupName.isEmpty());

                        attrGroups.add(groupName);
                    }

                    for (GroupInfo info : groups) {
                        Assert.assertTrue(
                                String.format("group '%s' is expected to be present",
                                        domainName + "\\" + info.getName()),
                                attrGroups.contains(domainName + "\\" + info.getName()));
                        if (providerHasAlias()) {
                            Assert.assertTrue(
                                    String.format("group '%s' is expected to be present",
                                            domainAlias + "\\" + info.getName()),
                                    attrGroups.contains(domainAlias + "\\" + info.getName()));
                        }
                    }
                }

            } else if (LAST_NAME_FRIENDLY_NAME.equalsIgnoreCase(attr.getAttrDefinition().getFriendlyName())) {
                Assert.assertNotNull(attr.getValues());
                Assert.assertEquals(1, attr.getValues().size());
                assertEqualsString(userInfo.getLastName(), attr.getValues().get(0));
            } else if (FIRST_NAME_FRIENDLY_NAME.equalsIgnoreCase(attr.getAttrDefinition().getFriendlyName())) {
                Assert.assertNotNull(attr.getValues());
                Assert.assertEquals(1, attr.getValues().size());
                assertEqualsString(userInfo.getFirstName(), attr.getValues().get(0));
            } else if (SUBJECT_TYPE_FRIENDLY_NAME
                    .equalsIgnoreCase(attr.getAttrDefinition().getFriendlyName())) {
                Assert.assertNotNull(attr.getValues());
                Assert.assertEquals(1, attr.getValues().size());
                assertEqualsString("false", attr.getValues().get(0));
            } else if (USER_PRINCIPAL_NAME_FRIENDLY_NAME
                    .equalsIgnoreCase(attr.getAttrDefinition().getFriendlyName())) {
                Assert.assertNotNull(attr.getValues());
                Assert.assertEquals(1, attr.getValues().size());
                assertEqualsString(userInfo.getName() + "@" + domainName, attr.getValues().get(0));
            }
        }

        // ---------------------
        // findDirectParentGroups, findNestedParentGroups
        // ---------------------
        Set<GroupInfo> groups = _usersToGroups.get(userInfo.getName());

        PrincipalGroupLookupInfo directParentGroups = localOsProvider
                .findDirectParentGroups(new PrincipalId(userInfo.getName(), domainName));

        validateGroupsSubset(groups, ((directParentGroups == null) ? null : directParentGroups.getGroups()),
                domainName, domainAlias);

        PrincipalGroupLookupInfo userGroups = localOsProvider
                .findNestedParentGroups(new PrincipalId(userInfo.getName(), domainName));

        validateGroupsSubset(groups, ((userGroups == null) ? null : userGroups.getGroups()), domainName,
                domainAlias);
    }
}

From source file:com.btobits.automator.fix.quickfix.bridge.FixConnectivity.java

public static boolean isSessionActive(final SessionID sessionID) {
    Assert.assertNotNull("FIX sessionID is not specified", sessionID);
    return Session.lookupSession(sessionID) == null ? false : true;
}

From source file:fll.web.WebTestUtils.java

public static WebClient getConversation() throws IOException, SAXException {
    final WebClient conversation = new WebClient();

    // always login first
    final Page loginPage = conversation.getPage(TestUtils.URL_ROOT + "login.jsp");
    Assert.assertTrue("Received non-HTML response from web server", loginPage.isHtmlPage());

    final HtmlPage loginHtml = (HtmlPage) loginPage;
    HtmlForm form = loginHtml.getFormByName("login");
    Assert.assertNotNull("Cannot find login form", form);

    final HtmlTextInput userTextField = form.getInputByName("user");
    userTextField.setValueAttribute(IntegrationTestUtils.TEST_USERNAME);

    final HtmlPasswordInput passTextField = form.getInputByName("pass");
    passTextField.setValueAttribute(IntegrationTestUtils.TEST_PASSWORD);

    final HtmlSubmitInput button = form.getInputByName("submit_login");
    final Page response = button.click();

    final URL responseURL = response.getUrl();
    final String address = responseURL.getPath();
    final boolean correctAddress;
    if (address.contains("login.jsp")) {
        correctAddress = false;//from  w ww .j a va 2  s . c  o m
    } else {
        correctAddress = true;
    }
    Assert.assertTrue("Unexpected URL after login: " + address, correctAddress);

    return conversation;
}

From source file:com.btobits.automator.fix.ant.task.FixDisconnectExpect.java

@Override
protected void validate() {
    Assert.assertTrue("Reference to FIX session is not specified", StringUtils.isNotBlank(refId));
    final Object obj = getProject().getReference(refId);
    Assert.assertNotNull("RefId[" + refId + "]. Failed to get FIX session.", obj);
    Assert.assertTrue("RefId[" + refId + "]. Unknown FIX session mode: " + obj.getClass().getSimpleName(),
            (obj instanceof FixSession));
    fixSession = (FixSession) obj;/*from   w  w w.j  a  v  a  2s  .c o  m*/
    // get FIX connectivity object
    conn = fixSession.getConnectivity();
    Assert.assertNotNull("RefId[" + refId + "]. getConnectivity() return NULL", conn);
}

From source file:org.openspaces.eviction.test.ClassSpecificOrderTest.java

@Test
public void inClassLRUReadTest() throws Exception {

    logger.info("write an object");
    gigaSpace.write(new SilverMedal(0));

    logger.info("fill the space with more than cache size object and red the original in the middle");
    for (int i = 1; i <= cacheSize + 10; i++) {
        if (i == (cacheSize / 2))
            gigaSpace.read(new SilverMedal(0));
        else/*from w  w  w. j  a  v a2  s . c o  m*/
            gigaSpace.write(new SilverMedal(i));
    }
    Assert.assertTrue("amount of objects in space is larger than cache size",
            gigaSpace.count(new Object()) == cacheSize);
    logger.info("assert the original object is still in cache");
    Assert.assertNotNull("silver medal 0 is not in space", gigaSpace.read(new SilverMedal(0)));
    logger.info("Test Passed");
}

From source file:org.springmodules.cache.config.ConfigAssert.java

/**
 * Asserts the given set of property values contains the expected property
 * value.//from   ww w . jav  a2 s  .  co  m
 * 
 * @param propertyValues
 *          the given set of property values
 * @param expectedPropertyValue
 *          the expected property value
 */
public static void assertPropertyIsPresent(MutablePropertyValues propertyValues,
        PropertyValue expectedPropertyValue) {

    String propertyName = expectedPropertyValue.getName();
    PropertyValue actualPropertyValue = propertyValues.getPropertyValue(propertyName);

    Assert.assertNotNull("Property " + StringUtils.quote(propertyName) + " not found", actualPropertyValue);

    Object expectedValue = expectedPropertyValue.getValue();
    Object actualValue = actualPropertyValue.getValue();
    String message = "<Property " + StringUtils.quote(propertyName) + ">";

    assertEquals(message, expectedValue, actualValue);
}

From source file:org.openspaces.eviction.test.LRUSingleOrderTest.java

@Test
public void modifyKeepsAnObjectTest() {
    logger.info("same as readKeepsAnObjectTest but modify the object instead of read it");

    SilverMedal silverMedal = new SilverMedal(0);
    gigaSpace.write(silverMedal);// w  ww .ja v  a  2 s.  com
    silverMedal.setContest("Butterfly 100m");
    for (int i = 1; i <= cacheSize + 10; i++) {
        if (i == (cacheSize / 2))
            gigaSpace.write(silverMedal);
        else
            gigaSpace.write(new SilverMedal(i));
    }
    Assert.assertEquals("amount of objects in space is larger than cache size", gigaSpace.count(new Object()),
            cacheSize);
    Assert.assertNotNull("silver medal 0 is not in space", gigaSpace.read(silverMedal));
    logger.info("Test Passed");
}

From source file:org.openxdata.server.service.impl.FormDownloadServiceTest.java

@Test
public void testGetStudyList_forUser() throws Exception {
    User user = userService.findUserByUsername("user");
    List<Object[]> studies = formDownloadService.getStudyList(user);
    Assert.assertNotNull("There are studies for ordinary user", studies);
    Assert.assertEquals("There are two studies", 2, studies.size());
    assertStudy(studies.get(0), new Integer(2), "Another Sample Study");
    assertStudy(studies.get(1), new Integer(1), "Sample Study");
}

From source file:com.btobits.automator.fix.quickfix.bridge.FixConnectivity.java

public static Session getSession(final SessionID sessionID) throws SessionNotFound {
    Assert.assertNotNull("FIX sessionID is not specified", sessionID);
    Assert.assertNotNull("FIX senderCompID is not specified", sessionID.getSenderCompID());
    Assert.assertNotNull("FIX targetCompID is not specified", sessionID.getTargetCompID());
    Assert.assertNotNull("FIX version is not specified", sessionID.getBeginString());

    final Session session = Session.lookupSession(sessionID);
    if (session == null) {
        throw new SessionNotFound("SenderCompID=" + sessionID.getSenderCompID() + " TargetCompID="
                + sessionID.getSenderCompID() + " ProtocolType=" + sessionID.getBeginString());
    }/*  w ww  .j av  a  2s .c  o  m*/
    return session;
}