Example usage for java.util Locale ROOT

List of usage examples for java.util Locale ROOT

Introduction

In this page you can find the example usage for java.util Locale ROOT.

Prototype

Locale ROOT

To view the source code for java.util Locale ROOT.

Click Source Link

Document

Useful constant for the root locale.

Usage

From source file:com.facebook.internal.ShareInternalUtilityTest.java

@Test
public void testRemoveNamespaceFromComplexOGJsonObject() {
    try {//w  w w  .  j a va 2s .  co m
        JSONObject testObject = getJsonOGActionTestObject();
        testObject = ShareInternalUtility.removeNamespacesFromOGJsonObject(testObject, false);
        JSONObject expectedResult = getJsonOGActionTestObjectWithoutNamespace();
        if (!simpleJsonObjComparer(testObject, expectedResult)) {
            fail(String.format(Locale.ROOT, "Actual: %s\nExpected: %s", testObject.toString(),
                    expectedResult.toString()));
        }
    } catch (JSONException ex) {
        // Fail
        assertNotNull(ex);
    }
}

From source file:examples.mail.IMAPUtils.java

/**
 * Parse the URI and use the details to connect to the IMAP(S) server and login.
 *
 * @param uri the URI to use, e.g. imaps://user:pass@imap.mail.yahoo.com/folder
 * or imaps://user:pass@imap.googlemail.com/folder
 * @param defaultTimeout initial timeout (in milliseconds)
 * @param listener for tracing protocol IO (may be null)
 * @return the IMAP client - connected and logged in
 * @throws IOException if any problems occur
 *//* w ww.ja v  a 2s  .  co m*/
static IMAPClient imapLogin(URI uri, int defaultTimeout, ProtocolCommandListener listener) throws IOException {
    final String userInfo = uri.getUserInfo();
    if (userInfo == null) {
        throw new IllegalArgumentException("Missing userInfo details");
    }

    String[] userpass = userInfo.split(":");
    if (userpass.length != 2) {
        throw new IllegalArgumentException("Invalid userInfo details: '" + userInfo + "'");
    }

    String username = userpass[0];
    String password = userpass[1];
    /*
     * If the initial password is:
     * '*' - replace it with a line read from the system console
     * '-' - replace it with next line from STDIN
     * 'ABCD' - if the input is all upper case, use the field as an environment variable name
     *
     * Note: there are no guarantees that the password cannot be snooped.
     *
     * Even using the console may be subject to memory snooping,
     * however it should be safer than the other methods.
     *
     * STDIN may require creating a temporary file which could be read by others
     * Environment variables may be visible by using PS
     */
    if ("-".equals(password)) { // stdin
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        password = in.readLine();
    } else if ("*".equals(password)) { // console
        Console con = System.console(); // Java 1.6
        if (con != null) {
            char[] pwd = con.readPassword("Password for " + username + ": ");
            password = new String(pwd);
        } else {
            throw new IOException("Cannot access Console");
        }
    } else if (password.equals(password.toUpperCase(Locale.ROOT))) { // environment variable name
        final String tmp = System.getenv(password);
        if (tmp != null) { // don't overwrite if variable does not exist (just in case password is all uppers)
            password = tmp;
        }
    }

    final IMAPClient imap;

    final String scheme = uri.getScheme();
    if ("imaps".equalsIgnoreCase(scheme)) {
        System.out.println("Using secure protocol");
        imap = new IMAPSClient(true); // implicit
    } else if ("imap".equalsIgnoreCase(scheme)) {
        imap = new IMAPClient();
    } else {
        throw new IllegalArgumentException("Invalid protocol: " + scheme);
    }
    final int port = uri.getPort();
    if (port != -1) {
        imap.setDefaultPort(port);
    }

    imap.setDefaultTimeout(defaultTimeout);

    if (listener != null) {
        imap.addProtocolCommandListener(listener);
    }

    final String server = uri.getHost();
    System.out.println("Connecting to server " + server + " on " + imap.getDefaultPort());

    try {
        imap.connect(server);
        System.out.println("Successfully connected");
    } catch (IOException e) {
        throw new RuntimeException("Could not connect to server.", e);
    }

    if (!imap.login(username, password)) {
        imap.disconnect();
        throw new RuntimeException("Could not login to server. Check login details.");
    }

    return imap;
}

From source file:com.grayfox.server.service.PoiServiceTest.java

@Test
@Transactional/*from w ww.j a  v  a 2s.  c  o  m*/
public void testGetNearestPoisByCategory() {
    Category category = new Category();
    category.setFoursquareId("4bf58dd8d48988d151941735");
    category.setName("Taco Place");
    category.setIconUrl("https://ss3.4sqi.net/img/categories_v2/food/taco_88.png");

    Poi p1 = new Poi();
    p1.setFoursquareId("4cdd6a06930af04d92fb9597");
    p1.setName("Taquera Los ?ngeles");
    p1.setLocation(Location.parse("19.04336700060403,-98.19716334342957"));
    p1.setCategories(new HashSet<>(Arrays.asList(category)));

    Poi p2 = new Poi();
    p2.setFoursquareId("4c3ce8087c1ee21ebd388d71");
    p2.setName("Antigua Taquera La Oriental");
    p2.setLocation(Location.parse("19.044926274591635,-98.19751471281052"));
    p2.setCategories(new HashSet<>(Arrays.asList(category)));

    List<Poi> expectedPois = Arrays.asList(p1, p2);
    List<Poi> actualPois = poiService.getNearestPoisByCategory(Location.parse("19.04365,-98.197968"), 800,
            category.getFoursquareId(), Locale.ROOT);

    assertThat(actualPois).isNotNull().isNotEmpty().doesNotContainNull().hasSameSizeAs(expectedPois)
            .containsOnlyElementsOf(expectedPois);
}

From source file:org.apache.olingo.odata2.fit.basic.ErrorResponseTest.java

@Override
protected ODataSingleProcessor createProcessor() throws ODataException {
    final ODataSingleProcessor processor = mock(ODataSingleProcessor.class);

    when(((ServiceDocumentProcessor) processor).readServiceDocument(any(GetServiceDocumentUriInfo.class),
            any(String.class))).thenThrow(new ODataRuntimeException("unit testing"));
    when(((MetadataProcessor) processor).readMetadata(any(GetMetadataUriInfo.class), any(String.class)))
            .thenThrow(new ODataRuntimeApplicationException("unit testing", Locale.ROOT,
                    HttpStatusCodes.FORBIDDEN));

    return processor;
}

From source file:com.useekm.indexing.postgis.PostgisIndexMatcher.java

/**
 * Indexing for statements where the object is a {@link Literal} will be done when the language matches
 * the returned value./*from ww  w  .ja v a 2 s. c  o  m*/
 * If the language is null it will match any literal. If the value is the string "NULL" it will
 * match only when {@link Literal#getLanguage()} is null.
 * <p>
 * Note that when the language is set, this matcher will only be used for indexing Literal objects (not for URI's).
 */
public void setLanguage(String language) {
    this.language = language == null ? null : language.toLowerCase(Locale.ROOT);
    validateTypeLanguage();
}

From source file:br.ufrj.ppgi.jemf.mobile.bean.Contact.java

/**
 * Set the language as String value.//from   ww  w. ja  v  a2  s  . c om
 * @param language
 */
public void setLanguageString(String language) {
    setLanguage(EnumLanguage.valueOf(language.toUpperCase(Locale.ROOT)));
}

From source file:org.elasticsearch.wildfly.WildflyIT.java

public void testTransportClient() throws URISyntaxException, IOException {
    try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
        final String str = String.format(Locale.ROOT,
                "http://localhost:38080/wildfly-%s%s/transport/employees/1", Version.CURRENT,
                Build.CURRENT.isSnapshot() ? "-SNAPSHOT" : "");
        final HttpPut put = new HttpPut(new URI(str));
        final String body;
        try (XContentBuilder builder = jsonBuilder()) {
            builder.startObject();//from w  ww .  ja  v  a2 s  . c  o m
            {
                builder.field("first_name", "John");
                builder.field("last_name", "Smith");
                builder.field("age", 25);
                builder.field("about", "I love to go rock climbing");
                builder.startArray("interests");
                {
                    builder.value("sports");
                    builder.value("music");
                }
                builder.endArray();
            }
            builder.endObject();
            body = builder.string();
        }
        put.setEntity(new StringEntity(body, ContentType.APPLICATION_JSON));
        try (CloseableHttpResponse response = client.execute(put)) {
            assertThat(response.getStatusLine().getStatusCode(), equalTo(201));
        }

        final HttpGet get = new HttpGet(new URI(str));
        try (CloseableHttpResponse response = client.execute(get);
                XContentParser parser = JsonXContent.jsonXContent.createParser(
                        new NamedXContentRegistry(ClusterModule.getNamedXWriteables()),
                        response.getEntity().getContent())) {
            final Map<String, Object> map = parser.map();
            assertThat(map.get("first_name"), equalTo("John"));
            assertThat(map.get("last_name"), equalTo("Smith"));
            assertThat(map.get("age"), equalTo(25));
            assertThat(map.get("about"), equalTo("I love to go rock climbing"));
            final Object interests = map.get("interests");
            assertThat(interests, instanceOf(List.class));
            @SuppressWarnings("unchecked")
            final List<String> interestsAsList = (List<String>) interests;
            assertThat(interestsAsList, containsInAnyOrder("sports", "music"));
        }
    }
}

From source file:com.grayfox.server.service.UserServiceTest.java

@Test
@Transactional//from   w w  w  .ja v  a2  s.  c o m
public void integrationTest() {
    loadMockdata();

    Credential expectedCredential = new Credential();
    expectedCredential.setFoursquareAccessToken("fakeToken");
    expectedCredential.setNew(true);

    Credential credential = userService.registerUsingFoursquare("fakeCode");

    assertThat(credential).isNotNull().isEqualToIgnoringGivenFields(expectedCredential, "accessToken", "id");
    assertThat(credential.getAccessToken()).isNotNull().isNotEmpty();
    assertThatThrownBy(() -> userService.getCompactSelf(credential.getAccessToken()))
            .isInstanceOf(ServiceException.class);
    assertThatThrownBy(() -> userService.getSelfLikes(credential.getAccessToken(), Locale.ROOT))
            .isInstanceOf(ServiceException.class);
    assertThatThrownBy(() -> userService.getSelfCompactFriends(credential.getAccessToken()))
            .isInstanceOf(ServiceException.class);
    assertThatThrownBy(() -> userService.getUserLikes(credential.getAccessToken(), "invalidId", Locale.ROOT))
            .isInstanceOf(ServiceException.class);
    assertThatThrownBy(() -> userService.addLike(credential.getAccessToken(), "id"))
            .isInstanceOf(ServiceException.class);
    assertThatThrownBy(() -> userService.removeLike(credential.getAccessToken(), "id"))
            .isInstanceOf(ServiceException.class);

    userService.generateProfileUsingFoursquare(credential);
    credential.setNew(false);

    assertThat(userService.registerUsingFoursquare("fakeCode")).isNotNull().isEqualTo(credential);

    User expectedUser = new User();
    expectedUser.setName("John");
    expectedUser.setLastName("Doe");
    expectedUser.setPhotoUrl("https://irs3.4sqi.net/img/user/300x300/photo.jpg");
    expectedUser.setFoursquareId("34468234");

    assertThat(userService.getCompactSelf(credential.getAccessToken())).isNotNull()
            .isEqualToIgnoringGivenFields(expectedUser, "id");

    Category selfLike = new Category();
    selfLike.setFoursquareId("4bf58dd8d48988d190941735");
    selfLike.setName("Museo histrico");
    selfLike.setIconUrl("https://ss3.4sqi.net/img/categories_v2/arts_entertainment/museum_history_88.png");
    List<Category> expectedSelfLikes = new ArrayList<>(Arrays.asList(selfLike));

    assertThat(userService.getSelfLikes(credential.getAccessToken(), Locale.ROOT)).isNotNull().isNotEmpty()
            .hasSameSizeAs(expectedSelfLikes).usingElementComparatorIgnoringFields("id")
            .containsExactlyElementsOf(expectedSelfLikes);
    assertThat(
            userService.getUserLikes(credential.getAccessToken(), expectedUser.getFoursquareId(), Locale.ROOT))
                    .isNotNull().isNotEmpty().hasSameSizeAs(expectedSelfLikes)
                    .usingElementComparatorIgnoringFields("id").containsExactlyElementsOf(expectedSelfLikes);

    User friend = new User();
    friend.setName("Jane");
    friend.setLastName("Doe");
    friend.setPhotoUrl("https://irs1.4sqi.net/img/user/300x300/photo.jpg");
    friend.setFoursquareId("94578235");
    List<User> expectedFriends = Arrays.asList(friend);

    assertThat(userService.getSelfCompactFriends(credential.getAccessToken())).isNotNull().isNotEmpty()
            .hasSameSizeAs(expectedFriends).usingElementComparatorIgnoringFields("id")
            .containsExactlyElementsOf(expectedFriends);

    Category friendLike = new Category();
    friendLike.setFoursquareId("4bf58dd8d48988d175941735");
    friendLike.setName("Gimnasio/Centro de fitness");
    friendLike.setIconUrl("https://ss3.4sqi.net/img/categories_v2/building/gym_88.png");
    List<Category> expectedFriendLikes = Arrays.asList(friendLike);

    assertThatThrownBy(() -> userService.getUserLikes(credential.getAccessToken(), "invalidId", Locale.ROOT))
            .isInstanceOf(ServiceException.class);
    assertThatThrownBy(() -> userService.getUserLikes(credential.getAccessToken(), "46jk35", Locale.ROOT))
            .isInstanceOf(ServiceException.class);
    assertThat(userService.getUserLikes(credential.getAccessToken(), friend.getFoursquareId(), Locale.ROOT))
            .isNotNull().isNotEmpty().hasSameSizeAs(expectedFriendLikes)
            .usingElementComparatorIgnoringFields("id").containsExactlyElementsOf(expectedFriendLikes);

    Category newSelfLike = new Category();
    newSelfLike.setFoursquareId("4bf58dd8d48988d151941735");
    newSelfLike.setName("Taco Place");
    newSelfLike.setIconUrl("https://ss3.4sqi.net/img/categories_v2/food/taco_88.png");

    userService.addLike(credential.getAccessToken(), newSelfLike.getFoursquareId());
    userService.removeLike(credential.getAccessToken(), selfLike.getFoursquareId());
    expectedSelfLikes.add(newSelfLike);
    expectedSelfLikes.remove(selfLike);

    assertThat(userService.getSelfLikes(credential.getAccessToken(), Locale.ROOT)).isNotNull().isNotEmpty()
            .hasSameSizeAs(expectedSelfLikes).usingElementComparatorIgnoringFields("id")
            .containsExactlyElementsOf(expectedSelfLikes);
}

From source file:org.exoplatform.utils.ExoWebAddress.java

/** parses given uriString. */
public ExoWebAddress(String address) {
    if (address == null) {
        throw new NullPointerException();
    }/*from   w  w  w .java2  s.c  om*/

    mScheme = "";
    mHost = "";
    mPort = -1;
    mPath = "/";
    mAuthInfo = "";

    Matcher m = sAddressPattern.matcher(address);
    String t;
    if (m.matches()) {
        t = m.group(MATCH_GROUP_SCHEME);
        if (t != null)
            mScheme = t.toLowerCase(Locale.ROOT);
        t = m.group(MATCH_GROUP_AUTHORITY);
        if (t != null)
            mAuthInfo = t;
        t = m.group(MATCH_GROUP_HOST);
        if (t != null)
            mHost = t;
        t = m.group(MATCH_GROUP_PORT);
        if (t != null && t.length() > 0) {
            // The ':' character is not returned by the regex.
            try {
                mPort = Integer.parseInt(t);
            } catch (NumberFormatException ex) {
                throw new ParseException("Incorrect port number");
            }
        }
        t = m.group(MATCH_GROUP_PATH);
        if (t != null && t.length() > 0) {
            /* handle busted myspace frontpage redirect with
               missing initial "/" */
            if (t.charAt(0) == '/') {
                mPath = t;
            } else {
                mPath = "/" + t;
            }
        }

    } else {
        // nothing found... outa here
        throw new ParseException("Incorrect address");
    }

    if ("".equals(mScheme))
        mScheme = ExoConstants.HTTP_PROTOCOL;
}

From source file:ch.algotrader.config.spring.ConfigLoader.java

/**
 * Loads system parameters.//from   ww w .  ja  v  a2s.co m
 * <ul>
 * <li>conf.properties</li>
 * <li>conf-core.properties</li>
 * <li>conf-fix.properties</li>
 * <li>conf-ib.properties</li>
 * <li>conf-bb.properties</li>
 * </ul>
 */
public static Map<String, String> load(final ResourceLoader resourceResolver) throws IOException {

    Assert.notNull(resourceResolver, "ResourcePatternResolver is null");

    Map<String, String> paramMap = new LinkedHashMap<>();
    String[] resourceNames = new String[] { "conf.properties", "conf-core.properties", "conf-fix.properties",
            "conf-ib.properties", "conf-bb.properties" };
    for (String resourceName : resourceNames) {
        Resource resource = resourceResolver.getResource("classpath:/" + resourceName);
        if (resource != null && resource.exists()) {
            ConfigLoader.loadResource(paramMap, resource);
        }
    }

    String strategyName = System.getProperty("strategyName");
    if (strategyName != null) {

        Resource resource = resourceResolver
                .getResource("classpath:/conf-" + strategyName.toLowerCase(Locale.ROOT) + ".properties");
        if (resource != null && resource.exists()) {
            ConfigLoader.loadResource(paramMap, resource);
        }
    }

    return paramMap;
}