Skip to content

Commit

Permalink
Merge pull request #698 from thushara35/b3
Browse files Browse the repository at this point in the history
taxonomy feature
  • Loading branch information
thushara35 committed Apr 29, 2016
2 parents bc66656 + 98a76f1 commit 2950324
Show file tree
Hide file tree
Showing 17 changed files with 1,094 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@
<property name="pattern">.*</property>
</filter>
</handler>

<!--This handler manage the meta data resource caching-->
<handler class="org.wso2.carbon.governance.registry.extensions.handlers.MetaDataCacheHandler" profiles="default,uddi-registry">
<filter class="org.wso2.carbon.registry.core.jdbc.handlers.filters.URLMatcher">
Expand All @@ -269,7 +268,7 @@
</filter>
</handler>

<handler class="org.wso2.carbon.registry.extensions.handlers.TaxonomyResourceHandler" profiles="default,uddi-registry">
<handler class="org.wso2.carbon.governance.taxonomy.handler.TaxonomyResourceHandler" profiles="default,uddi-registry">
<filter class="org.wso2.carbon.registry.core.jdbc.handlers.filters.MediaTypeMatcher">
<property name="mediaType">application/taxo+xml</property>
</filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
var resources = function(){
return {
css:['select2.min.css','common.css','sidepanel.css', 'bootstrap-dialog.min.css'],
js:['select2.full.min.js','sidepanel.js','greg-subscriptions-api.js','bootstrap-dialog.min.js']
js:['select2.full.min.js','sidepanel.js','greg-subscriptions-api.js','bootstrap-dialog.min.js'],
code:['taxonomy-meta-data.hbs']
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
{{> view-asset-top-common-addons-container .}}
{{> view-asset-details-container .}}
{{> view-asset-tags-container .}}
{{#if taxonomyAvailability}}
{{> taxonomy-overview .}}
{{/if}}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ var createQuery = function(options) {
var input = $('#inp_searchAsset').val();
var category = options.category || undefined;
var searchQueryString = '?';
input = setDefaultSearchQuery(input);
q = parseUsedDefinedQuery(input);
// if (name) {
// q.name = name;
Expand All @@ -133,6 +134,9 @@ var createQuery = function(options) {
}
return searchUrl + searchQueryString;
};
var setDefaultSearchQuery = function(query){
return "_default:" +query;
};
var initSearch = function() {
//Support for searching when pressing enter
$('#assetSearchForm').submit(function(e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>
if(!store.store){
store.store = {};
}
store.store.tenantDomain = '{{cuser.tenantDomain}}';
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,42 @@
*
*/

var resources = function () {
return {
css:['common.css','sidepanel.css', 'left-navigation.css', 'font-wso2.css', 'bootstrap-dialog.min.css', 'typeahead.css'],
js:['sidepanel.js','greg-subscriptions-api.js','bootstrap-dialog.min.js', 'typeahead.bundle.min.js', 'typeahead.js']
var name;
var hps = require('/themes/store/helpers/header.js');
var that = this;
/*
In order to inherit all variables in the default helper
*/
for (name in hps) {
if (hps.hasOwnProperty(name)) {
that[name] = hps[name];
}
}
var fn = that.resources||function() { return {} };
var resources = function(page, meta) {
var o = fn(page, meta);
if (!o.css) {
o.css = [];
}
if(!o.js){
o.js = [];
}
if(!o.code){
o.code = [];
}
o.css.push('common.css');
o.css.push('sidepanel.css');
o.css.push('left-navigation.css');
o.css.push('font-wso2.css');
o.css.push('bootstrap-dialog.min.css');
o.css.push('typeahead.css');
o.js.push('sidepanel.js');
o.js.push('greg-subscriptions-api.js');
o.js.push('bootstrap-dialog.min.js');
o.js.push('typeahead.bundle.min.js');
// remove this line, because this file is loaded twice in store side. That occurs search-box css issue
//o.js.push('typeahead.js');
o.code.push('taxonomy-meta-data.hbs');
o.code.push('tenant-meta-data.hbs');
return o;
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
{{/with}}
</nav>
<input id="categorization-query" type="hidden" value=""/>
{{> categorization-entry .}}
{{#if tags}}
<div class="tags-wrapper">
<div class="tag-title"> {{t "Tags"}} </div>
Expand All @@ -55,6 +56,7 @@
</div>
</div>
{{/if}}
{{#if assetCategoryFilterDetails}}<style>div.body-container{min-height: 1220px;}</style>{{/if}}
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
/*
*Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
*WSO2 Inc. licenses this file to you under the Apache License,
*Version 2.0 (the "License"); you may not use this file except
*in compliance with the License.
*You may obtain a copy of the License at
*
*http://www.apache.org/licenses/LICENSE-2.0
*
*Unless required by applicable law or agreed to in writing,
*software distributed under the License is distributed on an
*"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
*KIND, either express or implied. See the License for the
*specific language governing permissions and limitations
*under the License.
*/
package org.wso2.carbon.registry.es.publisher.category;

import org.apache.wink.client.ClientResponse;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.simple.parser.ParseException;
import org.testng.annotations.*;
import org.wso2.carbon.automation.engine.annotations.ExecutionEnvironment;
import org.wso2.carbon.automation.engine.annotations.SetEnvironment;
import org.wso2.carbon.automation.engine.context.TestUserMode;
import org.wso2.carbon.automation.engine.frameworkutils.FrameworkPathUtil;
import org.wso2.carbon.registry.es.utils.GregESTestBaseTest;
import org.wso2.greg.integration.common.utils.GenericRestClient;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.xml.xpath.XPathExpressionException;

import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;

/**
* This class can be used to test categorization(Filtering) related functionality
*/
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL})
public class GregRestResourceCategorizationTestCase extends GregESTestBaseTest {

private TestUserMode userMode;
private String publisherUrl;
private String resourcePath;
private String restServiceOneAssetId;
private String restServiceTwoAssetId;
private String type = "restservice";
private String restServiceName;
private GenericRestClient genericRestClient;
private Map<String, String> queryParamMap;
private Map<String, String> headerMap;
private String cookieHeader;

@Factory(dataProvider = "userModeProvider")
public GregRestResourceCategorizationTestCase(TestUserMode userMode) {
this.userMode = userMode;
}

@BeforeClass(alwaysRun = true)
public void init() throws Exception {
super.init(userMode);
genericRestClient = new GenericRestClient();
queryParamMap = new HashMap<>();
headerMap = new HashMap<>();
resourcePath =
FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "GREG" + File.separator;
publisherUrl = publisherContext.getContextUrls().getSecureServiceUrl().replace("services", "publisher/apis");
assertTrue(addNewRxtConfiguration("restserviceCategorization.rxt", "restservice.rxt"),
"Addition of new rest service rxt failed");

}

@AfterClass(alwaysRun = true)
public void cleanUp() throws Exception {
deleteAsset(restServiceOneAssetId, publisherUrl, cookieHeader, type, genericRestClient);
deleteAsset(restServiceTwoAssetId, publisherUrl, cookieHeader, type, genericRestClient);
assertTrue(defaultCustomRxtConfiguration("restservicedefault.rxt", "restservice.rxt"),
"Reverting back to default rest service rxt failed");
}

@Test(groups = {"wso2.greg", "wso2.greg.es"}, description = "Authenticate Publisher test")
public void authenticatePublisher() throws JSONException, XPathExpressionException {

ClientResponse response =
genericRestClient.geneticRestRequestPost(publisherUrl + "/authenticate/",
MediaType.APPLICATION_FORM_URLENCODED,
MediaType.APPLICATION_JSON,
"username=" + automationContext.getContextTenant().getContextUser().getUserName() +
"&password=" + automationContext.getContextTenant().getContextUser().getPassword()
, queryParamMap, headerMap, null
);
JSONObject obj = new JSONObject(response.getEntity(String.class));
assertTrue((response.getStatusCode() == Response.Status.OK.getStatusCode()),
"Wrong status code ,Expected 200 OK ,Received " +
response.getStatusCode()
);
String jSessionId = obj.getJSONObject("data").getString("sessionId");
cookieHeader = "JSESSIONID=" + jSessionId;
assertNotNull(jSessionId, "Invalid JSessionID received");
}


@Test(groups = {"wso2.greg", "wso2.greg.es"}, description = "Create Test Rest Service",
dependsOnMethods = {"authenticatePublisher"})
public void createTestRestServices() throws JSONException, IOException {
queryParamMap.put("type", type);
String dataBody = readFile(resourcePath + "json" + File.separator + "publisherPublishRestResource.json");
ClientResponse response =
genericRestClient.geneticRestRequestPost(publisherUrl + "/assets",
MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, dataBody
, queryParamMap, headerMap, cookieHeader);
JSONObject obj = new JSONObject(response.getEntity(String.class));
assertTrue((response.getStatusCode() == Response.Status.CREATED.getStatusCode()),
"Wrong status code ,Expected 201 Created ,Received " + response.getStatusCode());
restServiceOneAssetId = obj.get("id").toString();
restServiceName = obj.get("name").toString();

assertNotNull(restServiceOneAssetId, "Empty asset resource id available" +
response.getEntity(String.class));
}

@Test(groups = {"wso2.greg", "wso2.greg.es"}, description = "Adding Categorization To Existing Rest Service",
dependsOnMethods = {"createTestRestServices"})
public void addCategorizationToExistingRestService() throws JSONException, IOException, InterruptedException,
ParseException {

queryParamMap.clear();

queryParamMap.put("type", type);

String dataBody = readFile(resourcePath + "json" + File.separator +
"publisherPublishRestResourceWithCategorization.json");

ClientResponse response =
genericRestClient.geneticRestRequestPost(publisherUrl + "/assets/" + restServiceOneAssetId,
MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, dataBody,
queryParamMap, headerMap, cookieHeader);

JSONObject obj = new JSONObject(response.getEntity(String.class));

assertTrue((response.getStatusCode() == Response.Status.ACCEPTED.getStatusCode()),
"Wrong status code ,Expected 201 Created ,Received " + response.getStatusCode());

assertTrue(obj.get("attributes").toString().contains("overview_name" + "\":" + "\"" + restServiceName + "\""),
"Rest service name mismatched");

assertTrue(obj.get("attributes").toString().contains("categorization_product" + "\":" + "\"" + "g-reg" + "\""),
"Rest service updating to product g-reg was unsuccessful");

queryParamMap.put("paginationLimit", "20");
queryParamMap.put("start", "0");
queryParamMap.put("count", "20");
queryParamMap.put("q", "\"categorization_product" + "\":" + "\"" + "is" + "\"");

// Verify whether rest service lists incorrectly for irrelevant category
ClientResponse searchedIrrelevantCategoryResponse = genericRestClient.geneticRestRequestGet
(publisherUrl.split("/apis")[0] + "/apis/assets", queryParamMap, headerMap, cookieHeader);

JSONObject searchJsonObj = new JSONObject(searchedIrrelevantCategoryResponse.getEntity(String.class));
assertTrue(searchJsonObj.get("count").equals(0.0), "Search for product IS unsuccessful due to count should " +
"equal to zero");

queryParamMap.put("q", "\"categorization_product" + "\":" + "\"" + "g-reg" + "\"");

refreshPublisherLandingPage(publisherUrl, genericRestClient, cookieHeader);
Thread.sleep(10000);
// Verify whether rest service lists correctly for correct category
ClientResponse searchedRelevantCategoryResponse = genericRestClient.geneticRestRequestGet
(publisherUrl.split("/apis")[0] + "/apis/assets", queryParamMap, headerMap, cookieHeader);

JSONObject newSearchJsonObj = new JSONObject(searchedRelevantCategoryResponse.getEntity(String.class));
assertTrue(newSearchJsonObj.get("count").equals(1.0), "count should equal to 1");
assertTrue(newSearchJsonObj.get("list").toString().contains("testservice1234"),
"Search for product g-reg Rest service unsuccessful since unable to find testservice1234");

}

@Test(groups = {"wso2.greg", "wso2.greg.es"}, description = "Adding Category To New Rest Service",
dependsOnMethods = {"addCategorizationToExistingRestService"})
public void addCategorizationToNewRestService() throws JSONException, IOException, InterruptedException {

queryParamMap.clear();
queryParamMap.put("type", type);

String dataBody = readFile(resourcePath + "json" +
File.separator + "publisherPublishNewRestResourceWithCategorization.json");

ClientResponse response =
genericRestClient.geneticRestRequestPost(publisherUrl + "/assets",
MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, dataBody
, queryParamMap, headerMap, cookieHeader);

JSONObject obj = new JSONObject(response.getEntity(String.class));
assertTrue((response.getStatusCode() == Response.Status.CREATED.getStatusCode()),
"Wrong status code ,Expected 201 Created ,Received " + response.getStatusCode());
restServiceTwoAssetId = obj.get("id").toString();
restServiceName = obj.get("name").toString();

assertNotNull(restServiceTwoAssetId, "Empty asset resource id available" +
response.getEntity(String.class));

queryParamMap.put("paginationLimit", "20");
queryParamMap.put("start", "0");
queryParamMap.put("count", "20");
queryParamMap.put("q", "\"categorization_product" + "\":" + "\"" + "esb" + "\"");

refreshPublisherLandingPage(publisherUrl, genericRestClient, cookieHeader);
Thread.sleep(10000);

ClientResponse searchedNewlyAddedRestServiceResponse = genericRestClient.geneticRestRequestGet
(publisherUrl.split("/apis")[0] + "/apis/assets", queryParamMap, headerMap, cookieHeader);

JSONObject searchJsonObj = new JSONObject(searchedNewlyAddedRestServiceResponse.getEntity(String.class));
assertTrue(searchJsonObj.get("count").equals(1.0), "count should equal to 1");
assertTrue(searchJsonObj.get("list").toString().contains("MyTestRestService"),
"Search for product esb Rest service was unsuccessful since unable to find MyTestRestService");

}


@DataProvider
private static TestUserMode[][] userModeProvider() {
return new TestUserMode[][]{
new TestUserMode[]{TestUserMode.SUPER_TENANT_ADMIN}
// new TestUserMode[]{TestUserMode.TENANT_USER},
};
}
}
Loading

0 comments on commit 2950324

Please sign in to comment.