Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
berezovskyi committed Nov 5, 2024
1 parent e75e8db commit c03f7ef
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private synchronized void initializeRdf() {

infoResource = tryFindPrefixedResponseInfoUri(responseInfos);
if (infoResource == null) {
log.trace("Cannot find exactly one ResponseInfo whose URI starts with the query URI");
log.trace("Cannot find exactly one ResponseInfo whose URI starts with the query " + "URI");
} else {
log.debug("Found exactly one ResponseInfo whose URI starts with the query URI");
return;
Expand Down Expand Up @@ -211,8 +211,7 @@ private Resource tryFindPrefixedResponseInfoUri(List<Resource> responseInfos) {
if (filteredObjects.size() == 1) {
return filteredObjects.get(0);
} else if (filteredObjects.size() > 1) {
throw new IllegalStateException("Multiple ResponseInfo objects found starting with " +
"the same Query URI");
throw new IllegalStateException("Multiple ResponseInfo objects found starting with " + "the same Query URI");
}
return null;
}
Expand All @@ -231,8 +230,7 @@ private Resource tryFindExactResponseInfoUri(List<Resource> responseInfos) {
if (filteredObjects.size() == 1) {
return filteredObjects.get(0);
} else if (filteredObjects.size() > 1) {
throw new IllegalStateException("Multiple ResponseInfo objects found with the same " +
"URI");
throw new IllegalStateException("Multiple ResponseInfo objects found with the same " + "URI");
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,94 +13,97 @@
*/
package org.eclipse.lyo.client.query;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;

import java.io.InputStream;

import jakarta.ws.rs.core.Response;
import org.eclipse.lyo.client.OslcClient;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

import jakarta.ws.rs.core.Response;
import java.io.InputStream;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

/**
* @author Samuel Padgett <[email protected]>
*/
public class OslcQueryResultTest {
@Before
public void clearPublicURISystemProperty() {
System.clearProperty(OslcQueryResult.SELECT_ANY_MEMBER);
}

@Test
public void testEmpty() {
Response mockedResponse = mockClientResponse("/emptyQuery.rdf");

OslcQueryParameters params = new OslcQueryParameters();
params.setWhere("dceterms:identifier=3");
OslcQuery query = new OslcQuery(new OslcClient(), "http://example.com/provider/query", params);
OslcQueryResult result = new OslcQueryResult(query, mockedResponse);
assertEquals(0, result.getMembersUrls().length);
}

@Test
public void testNoParameters() {
Response mockedResponse = mockClientResponse("/noParamQuery.rdf");

OslcQuery query = new OslcQuery(new OslcClient(), "http://example.com/provider/query");
OslcQueryResult result = new OslcQueryResult(query, mockedResponse);
assertEquals(2, result.getMembersUrls().length);
}
@Before
public void clearPublicURISystemProperty() {
System.clearProperty(OslcQueryResult.SELECT_ANY_MEMBER);
}

@Test
public void testEmpty() {
Response mockedResponse = mockClientResponse("/emptyQuery.rdf");

OslcQueryParameters params = new OslcQueryParameters();
params.setWhere("dceterms:identifier=3");
OslcQuery query = new OslcQuery(new OslcClient(), "http://example.com/provider/query",
params);
OslcQueryResult result = new OslcQueryResult(query, mockedResponse);
assertEquals(0, result.getMembersUrls().length);
}

@Test
public void testNoParameters() {
Response mockedResponse = mockClientResponse("/noParamQuery.rdf");

OslcQuery query = new OslcQuery(new OslcClient(), "http://example.com/provider/query");
OslcQueryResult result = new OslcQueryResult(query, mockedResponse);
assertEquals(2, result.getMembersUrls().length);
}

@Test
public void testFolderQuery() {
Response mockedResponse = mockClientResponse("/queryFolderResponse.rdf");

OslcQueryParameters params = new OslcQueryParameters();
params.setPrefix("dcterms=<http://purl.org/dc/terms/>,nav=<http://jazz.net/ns/rm/navigation#>");
params.setPrefix("dcterms=<http://purl.org/dc/terms/>,nav=<http://jazz" +
".net/ns/rm/navigation#>");
params.setSelect("*");

OslcQuery query = new OslcQuery(new OslcClient(), "https://192.168.99.3:9443/rm/folders", params);
OslcQuery query = new OslcQuery(new OslcClient(), "https://192.168.99.3:9443/rm/folders",
params);
OslcQueryResult result = new OslcQueryResult(query, mockedResponse);
assertEquals(1, result.getMembersUrls().length);
}

@Test
public void testQuery() {
Response mockedResponse = mockClientResponse("/queryResponse.rdf");

OslcQueryParameters params = new OslcQueryParameters();
params.setWhere("ex:product=\"Product A\"");
OslcQuery query = new OslcQuery(new OslcClient(), "http://example.com/provider/query", params);
OslcQueryResult result = new OslcQueryResult(query, mockedResponse);
assertEquals(2, result.getMembersUrls().length);
}

@Test
public void testBlogQuery() {
Response mockedResponse = mockClientResponse("/blogQuery.rdf");

OslcQueryParameters params = new OslcQueryParameters();
params.setSelect("dcterms:title");
OslcQuery query = new OslcQuery(new OslcClient(), "http://example.com/query");
OslcQueryResult result = new OslcQueryResult(query, mockedResponse);
result.setMemberProperty("http://open-services.net/ns/bogus/blogs#comment");
assertEquals(5, result.getMembersUrls().length);
}

@Test
public void testAnyMember() {
System.setProperty(OslcQueryResult.SELECT_ANY_MEMBER, "true");
Response mockedResponse = mockClientResponse("/blogQuery.rdf");

OslcQueryParameters params = new OslcQueryParameters();
params.setSelect("dcterms:title");
OslcQuery query = new OslcQuery(new OslcClient(), "http://example.com/query");
OslcQueryResult result = new OslcQueryResult(query, mockedResponse);
assertEquals(5, result.getMembersUrls().length);
}
@Test
public void testQuery() {
Response mockedResponse = mockClientResponse("/queryResponse.rdf");

OslcQueryParameters params = new OslcQueryParameters();
params.setWhere("ex:product=\"Product A\"");
OslcQuery query = new OslcQuery(new OslcClient(), "http://example.com/provider/query",
params);
OslcQueryResult result = new OslcQueryResult(query, mockedResponse);
assertEquals(2, result.getMembersUrls().length);
}

@Test
public void testBlogQuery() {
Response mockedResponse = mockClientResponse("/blogQuery.rdf");

OslcQueryParameters params = new OslcQueryParameters();
params.setSelect("dcterms:title");
OslcQuery query = new OslcQuery(new OslcClient(), "http://example.com/query");
OslcQueryResult result = new OslcQueryResult(query, mockedResponse);
result.setMemberProperty("http://open-services.net/ns/bogus/blogs#comment");
assertEquals(5, result.getMembersUrls().length);
}

@Test
public void testAnyMember() {
System.setProperty(OslcQueryResult.SELECT_ANY_MEMBER, "true");
Response mockedResponse = mockClientResponse("/blogQuery.rdf");

OslcQueryParameters params = new OslcQueryParameters();
params.setSelect("dcterms:title");
OslcQuery query = new OslcQuery(new OslcClient(), "http://example.com/query");
OslcQueryResult result = new OslcQueryResult(query, mockedResponse);
assertEquals(5, result.getMembersUrls().length);
}

@Test
public void testMultiResponseInfos() {
Expand All @@ -110,17 +113,18 @@ public void testMultiResponseInfos() {

OslcQueryParameters params = new OslcQueryParameters();
params.setSelect("dcterms:title");
OslcQuery query = new OslcQuery(new OslcClient(), "https://nordic.clm.ibmcloud.com/ccm/oslc/contexts/_2nC4UBNvEeutmoeSPr3-Ag/workitems");
OslcQuery query = new OslcQuery(new OslcClient(), "https://nordic.clm.ibmcloud" +
".com/ccm/oslc/contexts/_2nC4UBNvEeutmoeSPr3-Ag/workitems");
OslcQueryResult result = new OslcQueryResult(query, mockedResponse);
assertEquals(20, result.getMembersUrls().length);
}

private Response mockClientResponse(String file) {
final InputStream is = OslcQueryResultTest.class.getResourceAsStream(file);
Response mockedResponse = Mockito.mock(Response.class);
when(mockedResponse.readEntity(InputStream.class)).thenReturn(is);
private Response mockClientResponse(String file) {
final InputStream is = OslcQueryResultTest.class.getResourceAsStream(file);
Response mockedResponse = Mockito.mock(Response.class);
when(mockedResponse.readEntity(InputStream.class)).thenReturn(is);

return mockedResponse;
return mockedResponse;
}

}

0 comments on commit c03f7ef

Please sign in to comment.