Example usage for java.net URI equals

List of usage examples for java.net URI equals

Introduction

In this page you can find the example usage for java.net URI equals.

Prototype

public boolean equals(Object ob) 

Source Link

Document

Tests this URI for equality with another object.

Usage

From source file:lh.api.showcase.server.lh.api.offers.OffersRequestFactoryImplTest.java

@Test
public void shouldConstructSeatMapsRequestUri() throws URISyntaxException {

    // e.g., https://api.lufthansa.com/v1/offers/seatmaps/LH741/KIX/FRA/2015-06-25/C
    OffersRequestFactoryImpl reqFact = new OffersRequestFactoryImpl();

    URI constructedUri = reqFact.getRequestUri((NameValuePair) new BasicNameValuePair("seatmaps", ""),
            (List<NameValuePair>) Arrays.asList((NameValuePair) new BasicNameValuePair("LH741", ""),
                    (NameValuePair) new BasicNameValuePair("KIX", ""),
                    (NameValuePair) new BasicNameValuePair("FRA", ""),
                    (NameValuePair) new BasicNameValuePair("2015-06-25", ""),
                    (NameValuePair) new BasicNameValuePair("C", "")),
            null);/*from  w w w. ja  v  a 2 s  . c o m*/
    URI referenceUri = new URI("https://api.lufthansa.com/v1/offers/seatmaps/LH741/KIX/FRA/2015-06-25/C");

    logger.log(Level.INFO, "constructed: " + constructedUri.toString());
    logger.log(Level.INFO, "reference: " + referenceUri.toString());
    assertTrue(referenceUri.equals(constructedUri));
}

From source file:org.kitodo.filemanagement.locking.ImmutableReadFileManagement.java

/**
 * Checks if the copy in question can be disposed of, and if so, does it. A
 * copy can be discarded if it isnt noted by any user more than his or her
 * visible version of this file. To find this out, the entire map must be
 * searched below the original URI. This process can be parallelized very
 * well. If the copy can be disposed of, it must first be removed from the
 * map of up-to-date copies so that it will not be reissued during the
 * deletion, and then deleted. If the file cannot be deleted, a warning is
 * written to the logfile. System administrators should be on the lookout
 * for such alerts, because if they occur frequently, this could signal that
 * the partiton is filling up with temporary files. This can be a problem
 * especially on Windows, because the Java virtual machine occasionally has
 * problems deleting files here.//from   w w  w . j  a v a2  s. c  o  m
 *
 * @param copyInQuestion
 *            URI of the file that may be deleted
 * @param originUri
 *            URI of the file of which the file in question is a copy. Since
 *            the maps storing the temporary file information use the URI of
 *            the source file as a key, they are much more efficient to use
 *            if it is known. (It would work without, but then you would
 *            have to chew through the whole map every time.)
 */
private void cleanUp(URI copyInQuestion, URI originUri) {
    UserMapForURI userMapForURI = urisGivenToUsers.get(originUri);
    if (Objects.isNull(userMapForURI) || userMapForURI.entrySet().parallelStream()
            .map(userMapForUriEntry -> userMapForUriEntry.getValue().getKey())
            .noneMatch(readCopy -> readCopy.equals(copyInQuestion))) {

        URI upToDateCopy = upToDateCopies.get(originUri);
        if (Objects.nonNull(upToDateCopy) && upToDateCopy.equals(copyInQuestion)) {
            upToDateCopies.remove(originUri);
        }

        File fileToDelete = new File(copyInQuestion.getPath());
        if (FileUtils.deleteQuietly(fileToDelete)) {
            logger.debug("the temporary read copy {} was deleted", fileToDelete);
        } else {
            logger.warn("The temporary read file {} could not be deleted.", fileToDelete);
        }
    }
}

From source file:lh.api.showcase.server.lh.api.opperations.OperationsRequestFactoryImplTest.java

@Test
public void shouldConstructFlightStatusRequestUri() throws URISyntaxException {

    // e.g., https://api.lufthansa.com/v1/operations/flightstatus/LH741/2015-06-25
    OperationsRequestFactoryImpl reqFact = new OperationsRequestFactoryImpl();

    URI constructedUri = reqFact.getRequestUri((NameValuePair) new BasicNameValuePair("flightstatus", ""),
            (List<NameValuePair>) Arrays.asList((NameValuePair) new BasicNameValuePair("LH741", ""),
                    (NameValuePair) new BasicNameValuePair("2015-06-25", "")),
            null);/*ww  w .j a  va2  s  . c  o  m*/

    URI referenceUri = new URI("https://api.lufthansa.com/v1/operations/flightstatus/LH741/2015-06-25");

    logger.log(Level.INFO, "constructed: " + constructedUri.toString());
    logger.log(Level.INFO, "reference: " + referenceUri.toString());
    assertTrue(referenceUri.equals(constructedUri));
}

From source file:org.eel.kitchen.jsonschema.ref.SchemaRegistryTest.java

@Test
public void namespacesAreRespected() throws IOException, JsonSchemaException {
    final URI fullPath = URI.create("foo:/baz#");
    final URIManager manager = new URIManager();
    final URIDownloader downloader = spy(new URIDownloader() {
        @Override//w w  w  .  j a v a  2s . co  m
        public InputStream fetch(final URI source) throws IOException {
            if (!fullPath.equals(source))
                throw new IOException();
            return new ByteArrayInputStream(JsonNodeFactory.instance.objectNode().toString().getBytes());
        }
    });
    manager.registerScheme("foo", downloader);

    final URI rootns = URI.create("foo:///bar/../bar/");

    final SchemaRegistry registry = new SchemaRegistry(manager, rootns);

    final URI uri = URI.create("../baz");
    registry.get(uri);
    final JsonRef ref = JsonRef.fromURI(rootns.resolve(uri));
    verify(downloader).fetch(rootns.resolve(ref.toURI()));
}

From source file:net.sf.taverna.t2.activities.wsdl.T2WSDLSOAPInvoker.java

protected void configureSecurity(Call call, JsonNode bean) throws Exception {

    // If security settings require WS-Security - configure the axis call
    // with appropriate properties
    URI securityProfile = new URI(bean.get("securityProfile").textValue());
    if (securityProfile.equals(SecurityProfiles.WSSECURITY_USERNAMETOKEN_PLAINTEXTPASSWORD)
            || securityProfile.equals(SecurityProfiles.WSSECURITY_USERNAMETOKEN_DIGESTPASSWORD)
            || securityProfile.equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_PLAINTEXTPASSWORD)
            || securityProfile.equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_DIGESTPASSWORD)) {

        UsernamePassword usernamePassword = getUsernameAndPasswordForService(bean, false);
        call.setProperty(Call.USERNAME_PROPERTY, usernamePassword.getUsername());
        call.setProperty(Call.PASSWORD_PROPERTY, usernamePassword.getPasswordAsString());
        usernamePassword.resetPassword();
    } else if (securityProfile.equals(SecurityProfiles.HTTP_BASIC_AUTHN)) {
        // Basic HTTP AuthN - set HTTP headers
        // pathrecursion allowed
        UsernamePassword usernamePassword = getUsernameAndPasswordForService(bean, true);
        MessageContext context = call.getMessageContext();
        context.setUsername(usernamePassword.getUsername());
        context.setPassword(usernamePassword.getPasswordAsString());
        usernamePassword.resetPassword();
    } else {// ww  w .  jav  a  2s.c o m
        logger.error("Unknown security profile " + securityProfile);
    }
}

From source file:com.almende.eve.transport.ws.WsClientTransport.java

@Override
public void send(final URI receiverUri, final String message, final String tag) throws IOException {
    if (!receiverUri.equals(serverUrl)) {
        throw new IOException(
                "Currently it's only possible to send to the server agent directly, not other agents:"
                        + receiverUri.toASCIIString() + " serverUrl:" + serverUrl.toASCIIString());
    }/*w  ww  . j  ava  2s .co m*/
    if (remote == null || !isConnected()) {
        connect();
    }
    if (remote != null) {
        try {
            remote.sendText(message);
            remote.flushBatch();
        } catch (RuntimeException rte) {
            if (rte.getMessage().equals("Socket is not connected.")) {
                remote = null;
                // retry!
                send(receiverUri, message, tag);
            }
        }
    } else {
        throw new IOException("Not connected?");
    }
}

From source file:com.almende.eve.transport.ws.WsClientTransport.java

@Override
public void send(final URI receiverUri, final byte[] message, final String tag) throws IOException {
    if (!receiverUri.equals(serverUrl)) {
        throw new IOException(
                "Currently it's only possible to send to the server agent directly, not other agents:"
                        + receiverUri.toASCIIString());
    }//  w ww . j a v  a  2  s  .  co m
    if (remote == null || !isConnected()) {
        connect();
    }
    if (remote != null) {
        try {
            remote.sendBinary(ByteBuffer.wrap(message));
            remote.flushBatch();
        } catch (RuntimeException rte) {
            if (rte.getMessage().equals("Socket is not connected.")) {
                remote = null;
                // retry!
                send(receiverUri, message, tag);
            }
        }
    } else {
        throw new IOException("Not connected?");
    }
}

From source file:lh.api.showcase.server.lh.api.opperations.OperationsRequestFactoryImplTest.java

@Test
public void shouldConstructScheduleRequestUri() throws URISyntaxException {

    // e.g., https://api.lufthansa.com/v1/operations/schedules/FRA/KIX/2014-11-01?directFlights=true
    OperationsRequestFactoryImpl reqFact = new OperationsRequestFactoryImpl();

    URI constructedUri = reqFact.getRequestUri((NameValuePair) new BasicNameValuePair("schedules", ""),
            (List<NameValuePair>) Arrays.asList((NameValuePair) new BasicNameValuePair("FRA", ""),
                    (NameValuePair) new BasicNameValuePair("KIX", ""),
                    (NameValuePair) new BasicNameValuePair("2014-11-01", "")),
            Arrays.asList((NameValuePair) new BasicNameValuePair("directFlights", "true")));
    URI referenceUri = new URI(
            "https://api.lufthansa.com/v1/operations/schedules/FRA/KIX/2014-11-01?directFlights=true");

    logger.log(Level.INFO, "constructed: " + constructedUri.toString());
    logger.log(Level.INFO, "reference: " + referenceUri.toString());
    assertTrue(referenceUri.equals(constructedUri));
}

From source file:org.topazproject.otm.NativeQueryTest.java

/**
 * DOCUMENT ME!/*from w  w w  . j ava 2  s .  c om*/
 */
@Test
public void testNativeQuery() throws OtmException {
    log.info("Testing native query ...");
    doInSession(new Action() {
        public void run(Session session) throws OtmException {
            String graph = factory.getClassMetadata(PublicAnnotation.class).getGraph();
            graph = factory.getGraph(graph).getUri().toString();

            session.doNativeUpdate(
                    "delete select $s $p $o from <" + graph + "> where $s $p $o from <" + graph + ">;");

            URI id1 = URI.create("http://localhost/annotation/1");
            URI id2 = URI.create("http://localhost/annotation/2");
            Annotation a1 = new PublicAnnotation(id1);
            Annotation a2 = new PublicAnnotation(id2);

            a1.setAnnotates(URI.create("foo:1"));
            a2.setAnnotates(URI.create("foo:1"));

            a1.setCreator("aa");
            a2.setCreator("bb");

            a1.setSupersededBy(a2);
            a2.setSupersedes(a1);

            a1.setTitle("foo");

            session.saveOrUpdate(a1);
            session.saveOrUpdate(a2);

            Results r = session.doNativeQuery("select $s $p $o from <" + graph + "> where $s $p $o;");
            Map m1 = new HashMap();
            Map m2 = new HashMap();

            while (r.next()) {
                URI s = r.getURI(0);
                URI p = r.getURI(1);
                String o = r.getString(2);

                if (s.equals(id1))
                    m1.put(p, o);
                else if (s.equals(id2))
                    m2.put(p, o);
                else
                    fail("Unknown subject-id");
            }

            r.close();

            assertEquals("foo:1", m1.get(URI.create(Annotea.NS + "annotates")));
            assertEquals("foo:1", m2.get(URI.create(Annotea.NS + "annotates")));
            assertEquals("aa", m1.get(URI.create(Rdf.dc + "creator")));
            assertEquals("bb", m2.get(URI.create(Rdf.dc + "creator")));
            assertEquals("foo", m1.get(URI.create(Rdf.dc + "title")));
            assertNull(m2.get(URI.create(Rdf.dc + "title")));
        }
    });
}

From source file:org.wrml.runtime.rest.UriTemplate.java

public boolean matches(final URI uri) {

    if (uri == null) {
        return false;
    }//from w w  w  . ja  v a2 s  . com

    final URI staticUri = getStaticUri();
    if (staticUri != null && uri.equals(staticUri)) {
        return true;
    }

    final String uriString = uri.normalize().toString();
    final Matcher matcher = getMatchPattern().matcher(uriString);

    return matcher.matches();
}