/*
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 * $Id: JAXRSClient.java 74172 2014-10-30 14:11:06Z supol $
 */
package com.sun.ts.tests.jaxrs.ee.rs.beanparam.query.plain;

import javax.ws.rs.core.Response.Status;

import com.sun.ts.tests.jaxrs.ee.rs.Constants;
import com.sun.ts.tests.jaxrs.ee.rs.beanparam.BeanParamCommonClient;

/*
 * @class.setup_props: webServerHost;
 *                     webServerPort;
 *                     ts_home;
 * @since 2.0.1
 */
public class JAXRSClient extends BeanParamCommonClient {

	private static final long serialVersionUID = 201L;

	public JAXRSClient() {
		setContextRoot("/jaxrs_ee_rs_beanparam_query_plain_web/resource");
	}

	/**
	 * Entry point for different-VM execution. It should delegate to method
	 * run(String[], PrintWriter, PrintWriter), and this method should not
	 * contain any test configuration.
	 */
	public static void main(String[] args) {
		new JAXRSClient().run(args);
	}

	/* Run test */

	/*
	 * @testName: queryParamEntityWithConstructorTest
	 * @assertion_ids: JAXRS:SPEC:3.2; JAXRS:SPEC:5.2;
	 *                 JAXRS:SPEC:12; JAXRS:SPEC:12.1;
	 * @test_Strategy: Verify that named QueryParam is handled properly
	 */
	public void queryParamEntityWithConstructorTest() throws Fault {
		super.paramEntityWithConstructorTest();
	}

	/*
	 * @testName: queryParamEntityWithValueOfTest
	 * @assertion_ids: JAXRS:SPEC:3.2; JAXRS:SPEC:5.3;
	 *                  JAXRS:SPEC:12; JAXRS:SPEC:12.1;
	 * @test_Strategy: Verify that named QueryParam is handled properly
	 */
	public void queryParamEntityWithValueOfTest() throws Fault {
		super.paramEntityWithValueOfTest();
	}

	/*
	 * @testName: queryParamEntityWithFromStringTest
	 * @assertion_ids: JAXRS:SPEC:3.2; JAXRS:SPEC:5.3;
	 *                  JAXRS:SPEC:12; JAXRS:SPEC:12.1;
	 * @test_Strategy: Verify that named QueryParam is handled properly
	 */
	public void queryParamEntityWithFromStringTest() throws Fault {
		super.paramEntityWithFromStringTest();
	}

	/*
	 * @testName: queryParamSetEntityWithFromStringTest
	 * @assertion_ids: JAXRS:SPEC:3.2; JAXRS:SPEC:5.4;
	 * 					JAXRS:SPEC:12; JAXRS:SPEC:12.1;
	 * @test_Strategy: Verify that named QueryParam is handled properly
	 */
	public void queryParamSetEntityWithFromStringTest() throws Fault {
		super.paramCollectionEntityWithFromStringTest(CollectionName.SET);
	}

	/*
	 * @testName: queryParamSortedSetEntityWithFromStringTest
	 * @assertion_ids: JAXRS:SPEC:3.2; JAXRS:SPEC:5.4;
	 * 					JAXRS:SPEC:12; JAXRS:SPEC:12.1;
	 * @test_Strategy: Verify that named QueryParam is handled properly
	 */
	public void queryParamSortedSetEntityWithFromStringTest() throws Fault {
		super.paramCollectionEntityWithFromStringTest(CollectionName.SORTED_SET);
	}

	/*
	 * @testName: queryParamListEntityWithFromStringTest
	 * @assertion_ids: JAXRS:SPEC:3.2; JAXRS:SPEC:5.4;
	 * 					JAXRS:SPEC:12; JAXRS:SPEC:12.1;
	 * @test_Strategy: Verify that named QueryParam is handled properly
	 */
	public void queryParamListEntityWithFromStringTest() throws Fault {
		super.paramCollectionEntityWithFromStringTest(CollectionName.LIST);
	}

	/*
	 * @testName: queryFieldParamEntityWithConstructorTest
	 * @assertion_ids: JAXRS:SPEC:3.2; JAXRS:SPEC:5.2;
	 *                 JAXRS:SPEC:6;
	 * @test_Strategy: Verify that named QueryParam is handled properly
	 */
	public void queryFieldParamEntityWithConstructorTest() throws Fault {
		super.fieldEntityWithConstructorTest();
	}

	/*
	 * @testName: queryFieldParamEntityWithValueOfTest
	 * @assertion_ids: JAXRS:SPEC:3.2; JAXRS:SPEC:5.3;
	 *                  JAXRS:SPEC:6;
	 * @test_Strategy: Verify that named QueryParam is handled properly
	 */
	public void queryFieldParamEntityWithValueOfTest() throws Fault {
		super.fieldEntityWithValueOfTest();
	}

	/*
	 * @testName: queryFieldParamEntityWithFromStringTest
	 * @assertion_ids: JAXRS:SPEC:3.2; JAXRS:SPEC:5.3;
	 *                  JAXRS:SPEC:6;
	 * @test_Strategy: Verify that named QueryParam is handled properly
	 */
	public void queryFieldParamEntityWithFromStringTest() throws Fault {
		super.fieldEntityWithFromStringTest();
	}

	/*
	 * @testName: queryFieldParamSetEntityWithFromStringTest
	 * @assertion_ids: JAXRS:SPEC:3.2; JAXRS:SPEC:5.4;
	 * 					JAXRS:SPEC:6;
	 * @test_Strategy: Verify that named QueryParam is handled properly
	 */
	public void queryFieldParamSetEntityWithFromStringTest() throws Fault {
		super.fieldCollectionEntityWithFromStringTest(CollectionName.SET);
	}

	/*
	 * @testName: queryFieldParamSortedSetEntityWithFromStringTest
	 * @assertion_ids: JAXRS:SPEC:3.2; JAXRS:SPEC:5.4;
	 * 					JAXRS:SPEC:6;
	 * @test_Strategy: Verify that named QueryParam is handled properly
	 */
	public void queryFieldParamSortedSetEntityWithFromStringTest() throws Fault {
		super.fieldCollectionEntityWithFromStringTest(CollectionName.SORTED_SET);
	}

	/*
	 * @testName: queryFieldParamListEntityWithFromStringTest
	 * @assertion_ids: JAXRS:SPEC:3.2; JAXRS:SPEC:5.4;
	 * 					JAXRS:SPEC:6;
	 * @test_Strategy: Verify that named QueryParam is handled properly
	 */
	public void queryFieldParamListEntityWithFromStringTest() throws Fault {
		super.fieldCollectionEntityWithFromStringTest(CollectionName.LIST);
	}

	/*
	 * @testName: queryParamEntityWithEncodedTest
	 * @assertion_ids: JAXRS:SPEC:3.2; JAXRS:SPEC:7;
	 * 					JAXRS:SPEC:12; JAXRS:SPEC:12.2;
	 * @test_Strategy: Verify that named QueryParam @Encoded is handled
	 */
	public void queryParamEntityWithEncodedTest() throws Fault {
		super.paramEntityWithEncodedTest();
	}

	/*
	 * @testName: queryFieldParamEntityWithEncodedTest
	 * @assertion_ids: JAXRS:SPEC:3.2; JAXRS:SPEC:7;
	 * @test_Strategy: Verify that named QueryParam @Encoded is handled
	 */
	public void queryFieldParamEntityWithEncodedTest() throws Fault {
		super.fieldEntityWithEncodedTest();
	}

	/*
	 * @testName: queryParamThrowingWebApplicationExceptionTest
	 * @assertion_ids: JAXRS:SPEC:12.3;
	 * @test_Strategy: Exceptions thrown during construction of parameter 
	 *   			   values are treated the same as exceptions thrown
	 *				   during construction of field or bean property values, 
	 *				   see Section 3.2.
	 */
	public void queryParamThrowingWebApplicationExceptionTest() throws Fault {
		super.paramThrowingWebApplicationExceptionTest();
		super.paramThrowingWebApplicationExceptionTest();
	}

	/*
	 * @testName: queryFieldThrowingWebApplicationExceptionTest
	 * @assertion_ids: JAXRS:SPEC:3.2; JAXRS:SPEC:8;
	 * @test_Strategy: A WebApplicationException thrown during construction of 
	 * 					field or property values using 2 or 3 above is 
	 * 					processed directly as described in section 3.3.4.
	 */
	public void queryFieldThrowingWebApplicationExceptionTest() throws Fault {
		super.fieldThrowingWebApplicationExceptionTest();
		super.fieldThrowingWebApplicationExceptionTest();
	}

	/*
	 * @testName: queryParamThrowingIllegalArgumentExceptionTest 
	 * @assertion_ids: JAXRS:SPEC:12.3;
	 * @test_Strategy: Exceptions thrown during construction of parameter values 
	 * 					are treated the same as exceptions thrown during 
	 * 					construction of field or bean property values, see 
	 * 					section 3.2.
	 */
	public void queryParamThrowingIllegalArgumentExceptionTest() throws Fault {
		setProperty(Property.UNORDERED_SEARCH_STRING, Status.NOT_FOUND.name());
		super.paramThrowingIllegalArgumentExceptionTest();
		setProperty(Property.UNORDERED_SEARCH_STRING, Status.NOT_FOUND.name());
		super.paramThrowingIllegalArgumentExceptionTest();
	}

	/*
	 * @testName: queryFieldThrowingIllegalArgumentExceptionTest 
	 * @assertion_ids: JAXRS:SPEC:9; JAXRS:SPEC:9.1; 
	 * 					JAXRS:SPEC:10;
	 * @test_Strategy: Other exceptions thrown during construction of field or 
	 * 					property values using 2 or 3 above are treated as client 
	 * 					errors:
	 * 
	 *					if the field or property is annotated with @MatrixParam, 
	 *					@QueryParam or @PathParam then an implementation MUST 
	 *					generate a WebApplicationException that wraps the thrown 
	 *					exception with a not found response (404 status) and no 
	 *					entity;
	 */
	public void queryFieldThrowingIllegalArgumentExceptionTest() throws Fault {
		setProperty(Property.UNORDERED_SEARCH_STRING, Status.NOT_FOUND.name());
		super.fieldThrowingIllegalArgumentExceptionTest();
		setProperty(Property.UNORDERED_SEARCH_STRING, Status.NOT_FOUND.name());
		super.fieldThrowingIllegalArgumentExceptionTest();
	}

	@Override
	protected String buildRequest(String param) {
		return buildRequest(Request.GET, fieldBeanParam, "?", param, "&",
				Constants.INNER, param);
	}

	@Override
	protected//
	String buildRequestForException(String param, int entity) throws Fault {
		if (entity == 1)
			return buildRequest(Request.GET, fieldBeanParam, "?", param);
		else
			return buildRequest(Request.GET, fieldBeanParam, "?",
					Constants.INNER, param);
	}

}
