// Path: moneta-core/src/main/java/org/moneta/config/MonetaEnvironment.java
// public class MonetaEnvironment extends BaseType {
// 	
// 	private static MonetaConfiguration configuration;
// 
// 	public static MonetaConfiguration getConfiguration() {
// 		return configuration;
// 	}
// 
// 	public static void setConfiguration(MonetaConfiguration configuration) {
// 		MonetaEnvironment.configuration = configuration;
// 	}
// 
// }
// 
// Path: moneta-core/src/main/java/org/moneta/types/search/CompositeCriteria.java
// public class CompositeCriteria extends BaseType implements Criteria {
// 	
// 	public static enum Operator {AND, OR};
// 	
// 	private Operator operator;
// 	private Criteria[] searchCriteria;
// 	
// 	public Operator getOperator() {
// 		return operator;
// 	}
// 	
// 	public void setOperator(Operator operator) {
// 		this.operator = operator;
// 	}
// 	
// 	public Criteria[] getSearchCriteria() {
// 		return searchCriteria;
// 	}
// 	
// 	public void setSearchCriteria(Criteria[] searchCriteria) {
// 		this.searchCriteria = searchCriteria;
// 	}
// 
// }
// 
// Path: moneta-core/src/main/java/org/moneta/types/search/Criteria.java
// public interface Criteria {
// 
// }
// 
// Path: moneta-core/src/main/java/org/moneta/types/search/FilterCriteria.java
// public class FilterCriteria extends BaseType implements Criteria {
// 	
// 	public static enum Operation {EQUAL, NOT_EQUAL, GREATER_THAN, LESS_THAN, IS_NULL, IS_NOT_NULL, LIKE};
// 	
// 	private String fieldName;
// 	private Operation operation;
// 	private Object value;
// 	
// 	public String getFieldName() {
// 		return fieldName;
// 	}
// 	
// 	public void setFieldName(String fieldName) {
// 		this.fieldName = fieldName;
// 	}
// 	
// 	public Operation getOperation() {
// 		return operation;
// 	}
// 	
// 	public void setOperation(Operation operation) {
// 		this.operation = operation;
// 	}
// 	
// 	public Object getValue() {
// 		return value;
// 	}
// 	
// 	public void setValue(Object value) {
// 		this.value = value;
// 	}
// 	
// 
// }
// 
// Path: moneta-core/src/main/java/org/moneta/types/search/SearchRequest.java
// public class SearchRequest extends BaseType {
// 	
// 	private String topic;
// 	private String[] fieldNames;
// 	private CompositeCriteria searchCriteria;
// 	private Long maxRows;
// 	private Long startRow;
// 	
// 	public String[] getFieldNames() {
// 		return fieldNames;
// 	}
// 	
// 	public void setFieldNames(String[] fieldNames) {
// 		this.fieldNames = fieldNames;
// 	}
// 	
// 	public CompositeCriteria getSearchCriteria() {
// 		return searchCriteria;
// 	}
// 	
// 	public void setSearchCriteria(CompositeCriteria searchCriteria) {
// 		this.searchCriteria = searchCriteria;
// 	}
// 
// 	public Long getMaxRows() {
// 		return maxRows;
// 	}
// 
// 	public void setMaxRows(Long maxRows) {
// 		this.maxRows = maxRows;
// 	}
// 
// 	public String getTopic() {
// 		return topic;
// 	}
// 
// 	public void setTopic(String topic) {
// 		this.topic = topic;
// 	}
// 
// 	public Long getStartRow() {
// 		return startRow;
// 	}
// 
// 	public void setStartRow(Long startRow) {
// 		this.startRow = startRow;
// 	}
// 
// 
// }


import java.util.Arrays;
import org.apache.commons.lang3.StringUtils;
import org.force66.mock.servletapi.MockRequest;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.moneta.config.MonetaEnvironment;
import org.moneta.types.search.CompositeCriteria;
import org.moneta.types.search.Criteria;
import org.moneta.types.search.FilterCriteria;
import org.moneta.types.search.SearchRequest;

/*
 * This software is licensed under the Apache License, Version 2.0
 * (the "License") agreement; 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.moneta;



public class SearchRequestFactoryTest extends MonetaTestBase {
	
	private SearchRequestFactory factory;
	private MockRequest request;

	@Before
	public void setUp() throws Exception {
		super.setUp();
		factory = new SearchRequestFactory();
		request = new MockRequest();
	}

	@Test
	public void testDeriveSearchRequest() throws Exception {
		request.setUri("/myapp", null);
		testException("Search topic not provided");
		
		request.setUri("/myapp", "/crap");
		testException("Topic not configured");
		testException("crap");
		
		request.setUri("/myapp", "/Environment/one/too/too/many");
		testException("Search key in request uri not configured");
		testException("many");
		
		request.setUri("/myapp", "/Environment/one/two/three");
		SearchRequest searchRequest = factory.deriveSearchRequest(request);
		Assert.assertTrue(searchRequest != null);
		Assert.assertTrue("Environment".equals(searchRequest.getTopic()));
		

// Path: moneta-core/src/main/java/org/moneta/config/MonetaEnvironment.java
// public class MonetaEnvironment extends BaseType {
// 	
// 	private static MonetaConfiguration configuration;
// 
// 	public static MonetaConfiguration getConfiguration() {
// 		return configuration;
// 	}
// 
// 	public static void setConfiguration(MonetaConfiguration configuration) {
// 		MonetaEnvironment.configuration = configuration;
// 	}
// 
// }
// 
// Path: moneta-core/src/main/java/org/moneta/types/search/CompositeCriteria.java
// public class CompositeCriteria extends BaseType implements Criteria {
// 	
// 	public static enum Operator {AND, OR};
// 	
// 	private Operator operator;
// 	private Criteria[] searchCriteria;
// 	
// 	public Operator getOperator() {
// 		return operator;
// 	}
// 	
// 	public void setOperator(Operator operator) {
// 		this.operator = operator;
// 	}
// 	
// 	public Criteria[] getSearchCriteria() {
// 		return searchCriteria;
// 	}
// 	
// 	public void setSearchCriteria(Criteria[] searchCriteria) {
// 		this.searchCriteria = searchCriteria;
// 	}
// 
// }
// 
// Path: moneta-core/src/main/java/org/moneta/types/search/Criteria.java
// public interface Criteria {
// 
// }
// 
// Path: moneta-core/src/main/java/org/moneta/types/search/FilterCriteria.java
// public class FilterCriteria extends BaseType implements Criteria {
// 	
// 	public static enum Operation {EQUAL, NOT_EQUAL, GREATER_THAN, LESS_THAN, IS_NULL, IS_NOT_NULL, LIKE};
// 	
// 	private String fieldName;
// 	private Operation operation;
// 	private Object value;
// 	
// 	public String getFieldName() {
// 		return fieldName;
// 	}
// 	
// 	public void setFieldName(String fieldName) {
// 		this.fieldName = fieldName;
// 	}
// 	
// 	public Operation getOperation() {
// 		return operation;
// 	}
// 	
// 	public void setOperation(Operation operation) {
// 		this.operation = operation;
// 	}
// 	
// 	public Object getValue() {
// 		return value;
// 	}
// 	
// 	public void setValue(Object value) {
// 		this.value = value;
// 	}
// 	
// 
// }
// 
// Path: moneta-core/src/main/java/org/moneta/types/search/SearchRequest.java
// public class SearchRequest extends BaseType {
// 	
// 	private String topic;
// 	private String[] fieldNames;
// 	private CompositeCriteria searchCriteria;
// 	private Long maxRows;
// 	private Long startRow;
// 	
// 	public String[] getFieldNames() {
// 		return fieldNames;
// 	}
// 	
// 	public void setFieldNames(String[] fieldNames) {
// 		this.fieldNames = fieldNames;
// 	}
// 	
// 	public CompositeCriteria getSearchCriteria() {
// 		return searchCriteria;
// 	}
// 	
// 	public void setSearchCriteria(CompositeCriteria searchCriteria) {
// 		this.searchCriteria = searchCriteria;
// 	}
// 
// 	public Long getMaxRows() {
// 		return maxRows;
// 	}
// 
// 	public void setMaxRows(Long maxRows) {
// 		this.maxRows = maxRows;
// 	}
// 
// 	public String getTopic() {
// 		return topic;
// 	}
// 
// 	public void setTopic(String topic) {
// 		this.topic = topic;
// 	}
// 
// 	public Long getStartRow() {
// 		return startRow;
// 	}
// 
// 	public void setStartRow(Long startRow) {
// 		this.startRow = startRow;
// 	}
// 
// 
// }


// Path: moneta-core/src/test/java/org/moneta/SearchRequestFactoryTest.java
import java.util.Arrays;
import org.apache.commons.lang3.StringUtils;
import org.force66.mock.servletapi.MockRequest;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.moneta.config.MonetaEnvironment;
import org.moneta.types.search.CompositeCriteria;
import org.moneta.types.search.Criteria;
import org.moneta.types.search.FilterCriteria;
import org.moneta.types.search.SearchRequest;

/*
 * This software is licensed under the Apache License, Version 2.0
 * (the "License") agreement; 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.moneta;



public class SearchRequestFactoryTest extends MonetaTestBase {
	
	private SearchRequestFactory factory;
	private MockRequest request;

	@Before
	public void setUp() throws Exception {
		super.setUp();
		factory = new SearchRequestFactory();
		request = new MockRequest();
	}

	@Test
	public void testDeriveSearchRequest() throws Exception {
		request.setUri("/myapp", null);
		testException("Search topic not provided");
		
		request.setUri("/myapp", "/crap");
		testException("Topic not configured");
		testException("crap");
		
		request.setUri("/myapp", "/Environment/one/too/too/many");
		testException("Search key in request uri not configured");
		testException("many");
		
		request.setUri("/myapp", "/Environment/one/two/three");
		SearchRequest searchRequest = factory.deriveSearchRequest(request);
		Assert.assertTrue(searchRequest != null);
		Assert.assertTrue("Environment".equals(searchRequest.getTopic()));
		

		CompositeCriteria searchCriteria = searchRequest.getSearchCriteria();
