-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e75e8db
commit c03f7ef
Showing
2 changed files
with
79 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() { | ||
|
@@ -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; | ||
} | ||
|
||
} |