Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse')
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/OrcsRestTestSuite.java24
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/InternalTestSuite.java35
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslTranslatorImplTest.java152
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchDslTest.java119
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/AttributeTypePredicateHandlerTest.java132
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/ExistsTypePredicateHandlerTest.java166
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IdsPredicateHandlerTest.java104
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IsOfTypePredicateHandlerTest.java81
-rw-r--r--plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/mocks/MockQueryBuilder.java228
9 files changed, 1041 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/OrcsRestTestSuite.java b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/OrcsRestTestSuite.java
new file mode 100644
index 00000000000..02b32e7bced
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/OrcsRestTestSuite.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.rest;
+
+import org.eclipse.osee.orcs.rest.internal.InternalTestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * @author John Misinco
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({InternalTestSuite.class,})
+public class OrcsRestTestSuite {
+ // Test Suite
+}
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/InternalTestSuite.java b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/InternalTestSuite.java
new file mode 100644
index 00000000000..234152a3b2f
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/InternalTestSuite.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.rest.internal;
+
+import org.eclipse.osee.orcs.rest.internal.search.dsl.DslTranslatorImplTest;
+import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchDslTest;
+import org.eclipse.osee.orcs.rest.internal.search.predicate.AttributeTypePredicateHandlerTest;
+import org.eclipse.osee.orcs.rest.internal.search.predicate.ExistsTypePredicateHandlerTest;
+import org.eclipse.osee.orcs.rest.internal.search.predicate.IdsPredicateHandlerTest;
+import org.eclipse.osee.orcs.rest.internal.search.predicate.IsOfTypePredicateHandlerTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * @author John Misinco
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ DslTranslatorImplTest.class,
+ SearchDslTest.class,
+ AttributeTypePredicateHandlerTest.class,
+ ExistsTypePredicateHandlerTest.class,
+ IdsPredicateHandlerTest.class,
+ IsOfTypePredicateHandlerTest.class,})
+public class InternalTestSuite {
+ // Test Suite
+}
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslTranslatorImplTest.java b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslTranslatorImplTest.java
new file mode 100644
index 00000000000..850994d979e
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/dsl/DslTranslatorImplTest.java
@@ -0,0 +1,152 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.rest.internal.search.dsl;
+
+import java.util.List;
+import java.util.Random;
+import junit.framework.Assert;
+import org.eclipse.osee.framework.core.exception.OseeArgumentException;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.orcs.rest.internal.search.Predicate;
+import org.junit.Test;
+
+/**
+ * @author John Misinco
+ */
+public class DslTranslatorImplTest {
+
+ @Test(expected = OseeArgumentException.class)
+ public void testBadSearchType() throws OseeCoreException {
+ DslTranslatorImpl translator = new DslTranslatorImpl();
+
+ //test bad search type
+ String test = "[t:attrTypes&tp:1000000000000070&op:==&v:AtsAdmin]";
+ translator.translate(test);
+ }
+
+ @Test(expected = OseeArgumentException.class)
+ public void testBadOp() throws OseeCoreException {
+ DslTranslatorImpl translator = new DslTranslatorImpl();
+
+ //test bad op
+ String test = "[t:attrType&tp:1000000000000070&op:<>&v:AtsAdmin]";
+ translator.translate(test);
+ }
+
+ @Test(expected = OseeArgumentException.class)
+ public void testBadFlag() throws OseeCoreException {
+ DslTranslatorImpl translator = new DslTranslatorImpl();
+
+ //test bad flags
+ String test = "[t:attrType&tp:1000000000000070&op:==&f:ti&v:AtsAdmin]";
+ translator.translate(test);
+ }
+
+ private int getNextInt(Random r) {
+ return Math.abs(r.nextInt());
+ }
+
+ private String getSearchMethod(Random r) {
+ int len = SearchMethod.values().length;
+ return SearchMethod.values()[getNextInt(r) % len].getToken();
+ }
+
+ private String getOp(Random r) {
+ int len = SearchOp.values().length;
+ return SearchOp.values()[getNextInt(r) % len].getToken();
+ }
+
+ private String getFlags(Random r, int num) {
+ if (num == 0) {
+ return "";
+ }
+ StringBuilder toReturn = new StringBuilder();
+ for (int i = 0; i < num; i++) {
+ int len = SearchFlag.values().length;
+ toReturn.append(SearchFlag.values()[getNextInt(r) % len].getToken());
+ toReturn.append(",");
+ }
+ int last = toReturn.length();
+ return toReturn.substring(0, last - 1);
+ }
+
+ private String getTestQuery(int num) {
+ Random r = new Random();
+ StringBuilder toReturn = new StringBuilder();
+ for (int i = 0; i < num; i++) {
+ toReturn.append("[t:");
+ toReturn.append(getSearchMethod(r));
+ toReturn.append("&tp:");
+ toReturn.append(r.nextLong());
+ toReturn.append("&op:");
+ toReturn.append(getOp(r));
+ toReturn.append("&f:");
+ toReturn.append(getFlags(r, getNextInt(r) % 3));
+ toReturn.append("&v:value1,value2]&");
+ }
+ int last = toReturn.length();
+ return toReturn.substring(0, last - 1);
+ }
+
+ private boolean compareStringToPredicate(String query, Predicate predicate) {
+ if (!query.contains(predicate.getType().getToken())) {
+ return false;
+ }
+ if (!query.contains(predicate.getOp().getToken())) {
+ return false;
+ }
+ for (SearchFlag flag : predicate.getFlags()) {
+ if (!query.contains(flag.getToken())) {
+ return false;
+ }
+ }
+ for (String typeParam : predicate.getTypeParameters()) {
+ if (!query.contains(typeParam)) {
+ return false;
+ }
+ }
+ for (String value : predicate.getValues()) {
+ if (!query.contains(value)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Test
+ public void testMultiplePredicates() throws OseeCoreException {
+ DslTranslatorImpl translator = new DslTranslatorImpl();
+ int size = 5;
+
+ String test = getTestQuery(size);
+ List<Predicate> translated = translator.translate(test);
+ Assert.assertEquals(size, translated.size());
+ String[] predicates = test.split("\\]&\\[");
+
+ for (int i = 0; i < size; i++) {
+ Assert.assertTrue(compareStringToPredicate(predicates[i], translated.get(i)));
+ }
+ }
+
+ @Test
+ public void testAttrTypeSearches() throws OseeCoreException {
+ DslTranslatorImpl translator = new DslTranslatorImpl();
+
+ String test = "[t:attrType&tp:0x1000000000000070&op:==&f:t,i&v:AtsAdmin]";
+ translator.translate(test);
+
+ test = "[t:attrType&tp:1000000000000070&op:!=&f:t,i&v:AtsAdmin]";
+ translator.translate(test);
+
+ test = "[t:attrType&tp:1000000000000070&op:<&f:t,i&v:AtsAdmin]";
+ translator.translate(test);
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchDslTest.java b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchDslTest.java
new file mode 100644
index 00000000000..2696b11c267
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/dsl/SearchDslTest.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.rest.internal.search.dsl;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.eclipse.osee.framework.core.data.IArtifactType;
+import org.eclipse.osee.framework.core.data.IOseeBranch;
+import org.eclipse.osee.framework.core.enums.CoreBranches;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.orcs.data.ReadableArtifact;
+import org.eclipse.osee.orcs.rest.internal.search.Predicate;
+import org.eclipse.osee.orcs.rest.internal.search.PredicateHandler;
+import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchDsl.DslTranslator;
+import org.eclipse.osee.orcs.search.QueryBuilder;
+import org.eclipse.osee.orcs.search.QueryFactory;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author John Misinco
+ */
+public class SearchDslTest {
+
+ private class MockTranslator implements DslTranslator {
+ public String rawString;
+ private final SearchMethod method;
+
+ public MockTranslator(SearchMethod method) {
+ this.method = method;
+ }
+
+ @Override
+ public List<Predicate> translate(String rawString) {
+ this.rawString = rawString;
+ Predicate toReturn = new Predicate(method, null, null, null, null);
+ return Collections.singletonList(toReturn);
+ }
+ }
+
+ private class MockPredicateHandler implements PredicateHandler {
+ public boolean handleCalled = false;
+
+ @Override
+ public QueryBuilder handle(QueryBuilder builder, Predicate predicate) {
+ handleCalled = true;
+ return builder;
+ }
+ }
+
+ private class MockQueryFactory implements QueryFactory {
+ public IOseeBranch branch;
+
+ @Override
+ public QueryBuilder fromBranch(IOseeBranch branch) {
+ this.branch = branch;
+ return null;
+ }
+
+ @Override
+ public QueryBuilder fromArtifactTypeAllBranches(IArtifactType artifactType) {
+ return null;
+ }
+
+ @Override
+ public QueryBuilder fromArtifacts(Collection<? extends ReadableArtifact> artifacts) {
+ return null;
+ }
+ };
+
+ @Test
+ public void testBuildValidSearchType() throws OseeCoreException {
+ Map<SearchMethod, PredicateHandler> handlers = new HashMap<SearchMethod, PredicateHandler>();
+ MockPredicateHandler handler = new MockPredicateHandler();
+ handlers.put(SearchMethod.ATTRIBUTE_TYPE, handler);
+
+ MockTranslator translator = new MockTranslator(SearchMethod.ATTRIBUTE_TYPE);
+ SearchDsl dsl = new SearchDsl(handlers, translator);
+ MockQueryFactory queryFactory = new MockQueryFactory();
+
+ IOseeBranch branch = CoreBranches.COMMON;
+ String rawQuery = "[t:attrType&tp:1000000000000070&op:==&v:AtsAdmin]";
+ dsl.build(queryFactory, branch, rawQuery);
+
+ Assert.assertEquals(rawQuery, translator.rawString);
+ Assert.assertEquals(branch, queryFactory.branch);
+ Assert.assertTrue(handler.handleCalled);
+ }
+
+ @Test
+ public void testBuildInvalidSearchType() throws OseeCoreException {
+ Map<SearchMethod, PredicateHandler> handlers = new HashMap<SearchMethod, PredicateHandler>();
+ MockPredicateHandler handler = new MockPredicateHandler();
+ handlers.put(SearchMethod.ATTRIBUTE_TYPE, handler);
+
+ MockTranslator translator = new MockTranslator(SearchMethod.EXISTS_TYPE);
+ SearchDsl dsl = new SearchDsl(handlers, translator);
+ MockQueryFactory queryFactory = new MockQueryFactory();
+
+ IOseeBranch branch = CoreBranches.COMMON;
+ String rawQuery = "[t:attrType&tp:1000000000000070&op:==&v:AtsAdmin]";
+ dsl.build(queryFactory, branch, rawQuery);
+
+ Assert.assertEquals(rawQuery, translator.rawString);
+ Assert.assertEquals(branch, queryFactory.branch);
+ Assert.assertFalse(handler.handleCalled);
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/AttributeTypePredicateHandlerTest.java b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/AttributeTypePredicateHandlerTest.java
new file mode 100644
index 00000000000..fe073e6ed5d
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/AttributeTypePredicateHandlerTest.java
@@ -0,0 +1,132 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.rest.internal.search.predicate;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import junit.framework.Assert;
+import org.eclipse.osee.framework.core.data.IAttributeType;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.orcs.rest.internal.search.Predicate;
+import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchFlag;
+import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchMethod;
+import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchOp;
+import org.eclipse.osee.orcs.rest.mocks.MockQueryBuilder;
+import org.eclipse.osee.orcs.search.CaseType;
+import org.eclipse.osee.orcs.search.Operator;
+import org.eclipse.osee.orcs.search.QueryBuilder;
+import org.eclipse.osee.orcs.search.StringOperator;
+import org.junit.Test;
+
+/**
+ * @author John Misinco
+ */
+public class AttributeTypePredicateHandlerTest {
+
+ private class TestAttributeTypePredicateHandler extends AttributeTypePredicateHandler {
+
+ StringOperator stringOperator;
+ Operator operator;
+ CaseType ct;
+
+ @Override
+ protected QueryBuilder and(QueryBuilder builder, Collection<IAttributeType> attributeTypes, StringOperator operator, CaseType ct, String value) {
+ this.stringOperator = operator;
+ this.ct = ct;
+ return builder;
+ }
+
+ @Override
+ protected QueryBuilder and(QueryBuilder builder, IAttributeType type, Operator operator, List<String> values) {
+ this.operator = operator;
+ return builder;
+ }
+
+ }
+
+ @Test
+ public void testStringOperatorSelection() throws OseeCoreException {
+ TestAttributeTypePredicateHandler handler = new TestAttributeTypePredicateHandler();
+ List<String> typeParameters = Collections.singletonList("0x0123");
+ List<SearchFlag> flags = Arrays.asList(SearchFlag.TOKENIZED_ANY);
+ List<String> values = Collections.singletonList("value");
+ Predicate testPredicate =
+ new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(StringOperator.TOKENIZED_ANY_ORDER, handler.stringOperator);
+
+ flags = Arrays.asList(SearchFlag.TOKENIZED_ORDERED);
+ testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(StringOperator.TOKENIZED_MATCH_ORDER, handler.stringOperator);
+
+ flags = Arrays.asList(SearchFlag.IGNORE_CASE);
+ testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(StringOperator.EQUALS, handler.stringOperator);
+
+ testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.NOT_EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(StringOperator.NOT_EQUALS, handler.stringOperator);
+
+ testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.IN, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(StringOperator.CONTAINS, handler.stringOperator);
+ }
+
+ @Test
+ public void testCaseTypeSelection() throws OseeCoreException {
+ TestAttributeTypePredicateHandler handler = new TestAttributeTypePredicateHandler();
+ List<String> typeParameters = Collections.singletonList("0x0123");
+ List<SearchFlag> flags = Arrays.asList(SearchFlag.IGNORE_CASE);
+ List<String> values = Collections.singletonList("value");
+ Predicate testPredicate =
+ new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(CaseType.IGNORE_CASE, handler.ct);
+
+ flags = Arrays.asList(SearchFlag.TOKENIZED, SearchFlag.IGNORE_CASE);
+ testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(CaseType.IGNORE_CASE, handler.ct);
+
+ flags = Arrays.asList(SearchFlag.TOKENIZED, SearchFlag.MATCH_CASE);
+ testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(CaseType.MATCH_CASE, handler.ct);
+ }
+
+ @Test
+ public void testOperatorSelection() throws OseeCoreException {
+ TestAttributeTypePredicateHandler handler = new TestAttributeTypePredicateHandler();
+ List<String> typeParameters = Collections.singletonList("0x0123");
+ List<SearchFlag> flags = Arrays.asList(SearchFlag.MATCH_CASE);
+ List<String> values = Collections.singletonList("value");
+ Predicate testPredicate =
+ new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(Operator.EQUAL, handler.operator);
+
+ testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.GREATER_THAN, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(Operator.GREATER_THAN, handler.operator);
+
+ testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.LESS_THAN, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(Operator.LESS_THAN, handler.operator);
+
+ testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.NOT_EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(Operator.NOT_EQUAL, handler.operator);
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/ExistsTypePredicateHandlerTest.java b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/ExistsTypePredicateHandlerTest.java
new file mode 100644
index 00000000000..e9d0759745d
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/ExistsTypePredicateHandlerTest.java
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.rest.internal.search.predicate;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import junit.framework.Assert;
+import org.eclipse.osee.framework.core.data.IAttributeType;
+import org.eclipse.osee.framework.core.data.IRelationTypeSide;
+import org.eclipse.osee.framework.core.enums.RelationSide;
+import org.eclipse.osee.framework.core.exception.OseeArgumentException;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.orcs.rest.internal.search.Predicate;
+import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchFlag;
+import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchMethod;
+import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchOp;
+import org.eclipse.osee.orcs.rest.mocks.MockQueryBuilder;
+import org.eclipse.osee.orcs.search.QueryBuilder;
+import org.junit.Test;
+
+/**
+ * @author John Misinco
+ */
+public class ExistsTypePredicateHandlerTest {
+
+ private class TestExistsTypePredicateHandler extends ExistsTypePredicateHandler {
+
+ Collection<IRelationTypeSide> relations;
+ Collection<IAttributeType> attributeTypes;
+
+ @Override
+ protected QueryBuilder andRelTypeSideExists(QueryBuilder builder, Collection<IRelationTypeSide> relations) {
+ this.relations = relations;
+ return builder;
+ }
+
+ @Override
+ protected QueryBuilder andAttrTypesExists(QueryBuilder builder, Collection<IAttributeType> attributeTypes) {
+ this.attributeTypes = attributeTypes;
+ return builder;
+ }
+
+ }
+
+ @Test
+ public void testHandleRelationTypeSides() throws OseeCoreException {
+ TestExistsTypePredicateHandler handler = new TestExistsTypePredicateHandler();
+ List<String> typeParameters = Collections.singletonList("relType");
+ //no flags for exists type
+ List<SearchFlag> flags = Collections.emptyList();
+ //for relation type sides, first char must be A or B denoting side, followed by relation type uuid
+ String relationValue = "A12345";
+ List<String> values = Collections.singletonList(relationValue);
+ Predicate testPredicate = new Predicate(SearchMethod.EXISTS_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+
+ Assert.assertEquals(1, handler.relations.size());
+ IRelationTypeSide side = handler.relations.iterator().next();
+ Assert.assertEquals(relationValue.substring(1), side.getGuid().toString());
+ Assert.assertEquals(RelationSide.SIDE_A, side.getSide());
+
+ //test side B
+ relationValue = "B12345";
+ values = Collections.singletonList(relationValue);
+ testPredicate = new Predicate(SearchMethod.EXISTS_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+
+ Assert.assertEquals(1, handler.relations.size());
+ side = handler.relations.iterator().next();
+ Assert.assertEquals(relationValue.substring(1), side.getGuid().toString());
+ Assert.assertEquals(RelationSide.SIDE_B, side.getSide());
+
+ //test multiples
+ String relationValue1 = "A12345";
+ String relationValue2 = "B34567";
+ values = Arrays.asList(relationValue1, relationValue2);
+ testPredicate = new Predicate(SearchMethod.EXISTS_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+
+ Assert.assertEquals(2, handler.relations.size());
+ boolean sideAMatched = false, sideBMatched = false;
+ for (IRelationTypeSide rts : handler.relations) {
+ if (rts.getSide() == RelationSide.SIDE_A) {
+ sideAMatched = true;
+ Assert.assertEquals(relationValue1.substring(1), rts.getGuid().toString());
+ }
+ if (rts.getSide() == RelationSide.SIDE_B) {
+ sideBMatched = true;
+ Assert.assertEquals(relationValue2.substring(1), rts.getGuid().toString());
+ }
+ }
+ Assert.assertTrue(sideAMatched);
+ Assert.assertTrue(sideBMatched);
+ }
+
+ @Test
+ public void testHandleAttrType() throws OseeCoreException {
+ TestExistsTypePredicateHandler handler = new TestExistsTypePredicateHandler();
+ List<String> typeParameters = Collections.singletonList("attrType");
+ //no flags for exists type
+ List<SearchFlag> flags = Collections.emptyList();
+ //for relation type sides, first char must be A or B denoting side, followed by relation type uuid
+ String attrUuid = "12345";
+ List<String> values = Collections.singletonList(attrUuid);
+ Predicate testPredicate = new Predicate(SearchMethod.EXISTS_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+
+ Assert.assertEquals(1, handler.attributeTypes.size());
+ IAttributeType type = handler.attributeTypes.iterator().next();
+ Assert.assertEquals(attrUuid, type.getGuid().toString());
+
+ //test multiples
+ String attrType1 = "12345";
+ String attrType2 = "34567";
+ values = Arrays.asList(attrType1, attrType2);
+ testPredicate = new Predicate(SearchMethod.EXISTS_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+
+ Assert.assertEquals(2, handler.attributeTypes.size());
+ boolean attr1Matched = false, attr2Matched = false;
+ for (IAttributeType attr : handler.attributeTypes) {
+ if (attr.getGuid().toString().equals(attrType1)) {
+ attr1Matched = true;
+ }
+ if (attr.getGuid().toString().equals(attrType2)) {
+ attr2Matched = true;
+ }
+ }
+ Assert.assertTrue(attr1Matched);
+ Assert.assertTrue(attr2Matched);
+ }
+
+ @Test(expected = OseeArgumentException.class)
+ public void testHandleBadValues() throws OseeCoreException {
+ TestExistsTypePredicateHandler handler = new TestExistsTypePredicateHandler();
+ List<String> typeParameters = Collections.singletonList("attrType");
+ //no flags for exists type
+ List<SearchFlag> flags = Collections.emptyList();
+ //for relation type sides, first char must be A or B denoting side, followed by relation type uuid
+ String value = "12A4G";
+ List<String> values = Collections.singletonList(value);
+ Predicate testPredicate = new Predicate(SearchMethod.EXISTS_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(0, handler.attributeTypes.size());
+
+ value = "A12A4G";
+ typeParameters = Collections.singletonList("relType");
+ values = Collections.singletonList(value);
+ testPredicate = new Predicate(SearchMethod.EXISTS_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ Assert.assertEquals(0, handler.relations.size());
+
+ testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, typeParameters, SearchOp.EQUALS, flags, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IdsPredicateHandlerTest.java b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IdsPredicateHandlerTest.java
new file mode 100644
index 00000000000..26d75c70e25
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IdsPredicateHandlerTest.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.rest.internal.search.predicate;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import junit.framework.Assert;
+import org.eclipse.osee.framework.core.exception.OseeArgumentException;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.orcs.rest.internal.search.Predicate;
+import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchMethod;
+import org.eclipse.osee.orcs.rest.mocks.MockQueryBuilder;
+import org.eclipse.osee.orcs.search.QueryBuilder;
+import org.junit.Test;
+
+/**
+ * @author John Misinco
+ */
+public class IdsPredicateHandlerTest {
+
+ private class TestIdsPredicateHandler extends IdsPredicateHandler {
+
+ Collection<String> guids;
+ Collection<Integer> rawIds;
+
+ @Override
+ protected QueryBuilder addGuids(QueryBuilder builder, Collection<String> guids) throws OseeCoreException {
+ this.guids = guids;
+ return builder;
+ }
+
+ @Override
+ protected QueryBuilder addIds(QueryBuilder builder, Collection<Integer> rawIds) throws OseeCoreException {
+ this.rawIds = rawIds;
+ return builder;
+ }
+
+ }
+
+ @Test
+ public void testHandle() throws OseeCoreException {
+ TestIdsPredicateHandler handler = new TestIdsPredicateHandler();
+ //no type params, op, or flags for ids - any passed are ignored
+
+ //all digits get treated as artId
+ String id1 = "12345";
+ List<String> values = Collections.singletonList(id1);
+ Predicate testPredicate = new Predicate(SearchMethod.IDS, null, null, null, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+
+ Assert.assertEquals(1, handler.rawIds.size());
+ Assert.assertNull(handler.guids);
+ Assert.assertEquals(id1, handler.rawIds.iterator().next().toString());
+
+ //if not all digits, treated as guid
+ handler = new TestIdsPredicateHandler();
+ String id2 = "AGUID234";
+ values = Collections.singletonList(id2);
+ testPredicate = new Predicate(SearchMethod.IDS, null, null, null, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+
+ Assert.assertNull(handler.rawIds);
+ Assert.assertEquals(1, handler.guids.size());
+ Assert.assertEquals(id2, handler.guids.iterator().next());
+
+ //test a rawId and guid
+ handler = new TestIdsPredicateHandler();
+ values = Arrays.asList(id1, id2);
+ testPredicate = new Predicate(SearchMethod.IDS, null, null, null, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+
+ Assert.assertEquals(1, handler.rawIds.size());
+ Assert.assertEquals(1, handler.guids.size());
+ Assert.assertEquals(id1, handler.rawIds.iterator().next().toString());
+ Assert.assertEquals(id2, handler.guids.iterator().next());
+
+ }
+
+ @Test(expected = OseeArgumentException.class)
+ public void testHandleBadValues() throws OseeCoreException {
+ TestIdsPredicateHandler handler = new TestIdsPredicateHandler();
+ Predicate testPredicate = new Predicate(SearchMethod.IDS, null, null, null, null);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ }
+
+ @Test(expected = OseeArgumentException.class)
+ public void testBadSearchMethod() throws OseeCoreException {
+ TestIdsPredicateHandler handler = new TestIdsPredicateHandler();
+ String id1 = "12345";
+ List<String> values = Collections.singletonList(id1);
+ Predicate testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, null, null, null, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IsOfTypePredicateHandlerTest.java b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IsOfTypePredicateHandlerTest.java
new file mode 100644
index 00000000000..963bc66246a
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/internal/search/predicate/IsOfTypePredicateHandlerTest.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.rest.internal.search.predicate;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import junit.framework.Assert;
+import org.eclipse.osee.framework.core.data.IArtifactType;
+import org.eclipse.osee.framework.core.exception.OseeArgumentException;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.orcs.rest.internal.search.Predicate;
+import org.eclipse.osee.orcs.rest.internal.search.dsl.SearchMethod;
+import org.eclipse.osee.orcs.rest.mocks.MockQueryBuilder;
+import org.eclipse.osee.orcs.search.QueryBuilder;
+import org.junit.Test;
+
+/**
+ * @author John Misinco
+ */
+public class IsOfTypePredicateHandlerTest {
+
+ private class TestIsOfTypePredicateHandler extends IsOfTypePredicateHandler {
+
+ Collection<IArtifactType> artTypes;
+
+ @Override
+ protected QueryBuilder andIsOfType(QueryBuilder builder, Collection<IArtifactType> artTypes) {
+ this.artTypes = artTypes;
+ return builder;
+ }
+
+ }
+
+ @Test
+ public void testHandle() throws OseeCoreException {
+ TestIsOfTypePredicateHandler handler = new TestIsOfTypePredicateHandler();
+ //no type params, op, or flags for ids - any passed are ignored
+
+ String id1 = "12345";
+ List<String> values = Collections.singletonList(id1);
+ Predicate testPredicate = new Predicate(SearchMethod.IS_OF_TYPE, null, null, null, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+
+ Assert.assertEquals(1, handler.artTypes.size());
+ Assert.assertEquals(id1, handler.artTypes.iterator().next().getGuid().toString());
+
+ String id2 = "45678";
+ values = Arrays.asList(id1, id2);
+
+ testPredicate = new Predicate(SearchMethod.IS_OF_TYPE, null, null, null, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+
+ Assert.assertEquals(2, handler.artTypes.size());
+ }
+
+ @Test(expected = OseeArgumentException.class)
+ public void testHandleBadValues() throws OseeCoreException {
+ TestIsOfTypePredicateHandler handler = new TestIsOfTypePredicateHandler();
+ Predicate testPredicate = new Predicate(SearchMethod.IS_OF_TYPE, null, null, null, null);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ }
+
+ @Test(expected = OseeArgumentException.class)
+ public void testBadSearchMethod() throws OseeCoreException {
+ TestIsOfTypePredicateHandler handler = new TestIsOfTypePredicateHandler();
+ String id1 = "12345";
+ List<String> values = Collections.singletonList(id1);
+ Predicate testPredicate = new Predicate(SearchMethod.ATTRIBUTE_TYPE, null, null, null, values);
+ handler.handle(new MockQueryBuilder(), testPredicate);
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/mocks/MockQueryBuilder.java b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/mocks/MockQueryBuilder.java
new file mode 100644
index 00000000000..1c49692b598
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest.test/src/org/eclipse/osee/orcs/rest/mocks/MockQueryBuilder.java
@@ -0,0 +1,228 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.rest.mocks;
+
+import java.util.Collection;
+import org.eclipse.osee.executor.admin.CancellableCallable;
+import org.eclipse.osee.framework.core.data.IArtifactToken;
+import org.eclipse.osee.framework.core.data.IArtifactType;
+import org.eclipse.osee.framework.core.data.IAttributeType;
+import org.eclipse.osee.framework.core.data.IRelationTypeSide;
+import org.eclipse.osee.framework.core.data.ResultSet;
+import org.eclipse.osee.orcs.data.ReadableArtifact;
+import org.eclipse.osee.orcs.data.ReadableAttribute;
+import org.eclipse.osee.orcs.search.CaseType;
+import org.eclipse.osee.orcs.search.Match;
+import org.eclipse.osee.orcs.search.Operator;
+import org.eclipse.osee.orcs.search.QueryBuilder;
+import org.eclipse.osee.orcs.search.StringOperator;
+
+/**
+ * @author John Misinco
+ */
+public class MockQueryBuilder implements QueryBuilder {
+
+ @Override
+ public QueryBuilder includeCache() {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder includeCache(boolean enabled) {
+ return this;
+ }
+
+ @Override
+ public boolean isCacheIncluded() {
+ return false;
+ }
+
+ @Override
+ public QueryBuilder includeDeleted() {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder includeDeleted(boolean enabled) {
+ return this;
+ }
+
+ @Override
+ public boolean areDeletedIncluded() {
+ return false;
+ }
+
+ @Override
+ public QueryBuilder includeTypeInheritance() {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder includeTypeInheritance(boolean enabled) {
+ return this;
+ }
+
+ @Override
+ public boolean isTypeInheritanceIncluded() {
+ return false;
+ }
+
+ @Override
+ public QueryBuilder fromTransaction(int transactionId) {
+ return this;
+ }
+
+ @Override
+ public int getFromTransaction() {
+ return 0;
+ }
+
+ @Override
+ public QueryBuilder headTransaction() {
+ return this;
+ }
+
+ @Override
+ public boolean isHeadTransaction() {
+ return false;
+ }
+
+ @Override
+ public QueryBuilder excludeCache() {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder excludeDeleted() {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder excludeTypeInheritance() {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder resetToDefaults() {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andLocalId(int... artifactId) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andLocalIds(Collection<Integer> artifactIds) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andGuidsOrHrids(String... ids) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andGuidsOrHrids(Collection<String> ids) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andIds(IArtifactToken... artifactToken) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andIds(Collection<? extends IArtifactToken> artifactTokens) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andIsOfType(IArtifactType... artifactType) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andIsOfType(Collection<? extends IArtifactType> artifactType) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andExists(IAttributeType... attributeType) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andExists(Collection<? extends IAttributeType> attributeTypes) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andExists(IRelationTypeSide relationType) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder andNameEquals(String artifactName) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder and(IAttributeType attributeType, Operator operator, String value) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder and(IAttributeType attributeType, Operator operator, Collection<String> values) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder and(IAttributeType attributeType, StringOperator operator, CaseType match, String value) {
+ return this;
+ }
+
+ @Override
+ public QueryBuilder and(Collection<? extends IAttributeType> attributeTypes, StringOperator operator, CaseType match, String value) {
+ return this;
+ }
+
+ @Override
+ public ResultSet<ReadableArtifact> getResults() {
+ return null;
+ }
+
+ @Override
+ public ResultSet<Match<ReadableArtifact, ReadableAttribute<?>>> getMatches() {
+ return null;
+ }
+
+ @Override
+ public int getCount() {
+ return 0;
+ }
+
+ @Override
+ public CancellableCallable<Integer> createCount() {
+ return null;
+ }
+
+ @Override
+ public CancellableCallable<ResultSet<ReadableArtifact>> createSearch() {
+ return null;
+ }
+
+ @Override
+ public CancellableCallable<ResultSet<Match<ReadableArtifact, ReadableAttribute<?>>>> createSearchWithMatches() {
+ return null;
+ }
+
+} \ No newline at end of file

Back to the top