/*
 * Copyright 2010 James Pether Sörling
 *
 * Licensed 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.
 *
 *	$Id$
 *  $HeadURL$
*/
package com.hack23.cia.service.impl.action.admin;

import java.util.UUID;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration;
import com.hack23.cia.model.internal.application.system.impl.ConfigurationGroup;
import com.hack23.cia.service.api.action.admin.UpdateApplicationConfigurationRequest;
import com.hack23.cia.service.api.action.admin.UpdateApplicationConfigurationResponse;
import com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest;
import com.hack23.cia.service.api.action.common.ServiceResponse.ServiceResult;
import com.hack23.cia.service.data.api.ApplicationConfigurationService;
import com.hack23.cia.service.impl.AbstractServiceFunctionalIntegrationTest;

/**
 * The Class UpdateApplicationConfigurationServiceITest.
 */
public final class UpdateApplicationConfigurationServiceITest extends AbstractServiceFunctionalIntegrationTest {

	/** The application configuration service. */
	@Autowired
	private ApplicationConfigurationService applicationConfigurationService;


	/**
	 * Success test.
	 *
	 * @throws Exception
	 *             the exception
	 */
	@Test
	public void successTest() throws Exception {

		setAuthenticatedAdminuser();
		final CreateApplicationSessionRequest createTestApplicationSession = createTestApplicationSession();

		final String randomUUID = UUID.randomUUID().toString();
		final ApplicationConfiguration applicationConfigurationToUpdate = applicationConfigurationService.checkValueOrLoadDefault(
				"UpdateApplicationRequestTest property",
				"UpdateApplicationRequestTest should be set to true/false",
				ConfigurationGroup.AUTHORIZATION, UpdateApplicationConfigurationServiceITest.class.getSimpleName(),
				"UpdateApplicationConfigurationService ITest", "FunctionalIntegrationTest",
				"UpdateApplicationRequestTest." + randomUUID, "true");


		final UpdateApplicationConfigurationRequest serviceRequest = new UpdateApplicationConfigurationRequest();
		serviceRequest.setApplicationConfigurationId(applicationConfigurationToUpdate.getHjid());
		serviceRequest.setSessionId(createTestApplicationSession.getSessionId());

		serviceRequest.setComponentDescription("componentDescription");
		serviceRequest.setConfigDescription("configDescription");
		serviceRequest.setConfigTitle("configTitle");
		serviceRequest.setComponentTitle("componentTitle");
		serviceRequest.setPropertyValue("false");

		final UpdateApplicationConfigurationResponse  response = (UpdateApplicationConfigurationResponse) applicationManager.service(serviceRequest);


		assertNotNull(EXPECT_A_RESULT,response);
		assertEquals(EXPECT_SUCCESS, ServiceResult.SUCCESS,response.getResult());


		final ApplicationConfiguration applicationConfigurationUpdated = applicationConfigurationService.checkValueOrLoadDefault(
				"UpdateApplicationRequestTest property",
				"UpdateApplicationRequestTest should be set to true/false",
				ConfigurationGroup.AUTHORIZATION, UpdateApplicationConfigurationServiceITest.class.getSimpleName(),
				"UpdateApplicationConfigurationService ITest", "FunctionalIntegrationTest",
				"UpdateApplicationRequestTest." + randomUUID, "true");


		assertEquals("false",applicationConfigurationUpdated.getPropertyValue());
		assertEquals("configTitle",applicationConfigurationUpdated.getConfigTitle());
		assertEquals("configDescription",applicationConfigurationUpdated.getConfigDescription());
		assertEquals("componentTitle",applicationConfigurationUpdated.getComponentTitle());
		assertEquals("componentDescription",applicationConfigurationUpdated.getComponentDescription());

	}

	/**
	 * Service request validation failure test.
	 *
	 * @throws Exception
	 *             the exception
	 */
	@Test
	public void serviceRequestValidationFailureTest() throws Exception {
		setAuthenticatedAdminuser();
		final UpdateApplicationConfigurationRequest serviceRequest = new UpdateApplicationConfigurationRequest();
		serviceRequest.setComponentDescription("componentDescription");
		serviceRequest.setConfigDescription("configDescription");
		serviceRequest.setConfigTitle("configTitle");
		serviceRequest.setComponentTitle("componentTitle");
		serviceRequest.setPropertyValue("false");

		final UpdateApplicationConfigurationResponse  response = (UpdateApplicationConfigurationResponse) applicationManager.service(serviceRequest);

		assertNotNull(EXPECT_A_RESULT,response);
		assertEquals(EXPECT_SUCCESS, ServiceResult.FAILURE,response.getResult());
		assertEquals("sessionId must not be null", response.getErrorMessage());
	}

}

@@ -5235,10 +5235,1085 @@
 ));%0A%09%7D%0A%0A
+%09/**%0A%09 * Failure config do not exist test.%0A%09 *%0A%09 * @throws Exception the exception%0A%09 */%0A%09@Test%0A%09public void failureConfigDoNotExistTest() throws Exception %7B%0A%0A%09%09setAuthenticatedAdminuser();%0A%09%09final CreateApplicationSessionRequest createTestApplicationSession = createTestApplicationSession();%0A%0A%09%0A%09%09final UpdateApplicationConfigurationRequest serviceRequest = new UpdateApplicationConfigurationRequest();%0A%09%09serviceRequest.setApplicationConfigurationId(-1L);%0A%09%09serviceRequest.setSessionId(createTestApplicationSession.getSessionId());%0A%0A%09%09serviceRequest.setComponentDescription(%22componentDescription%22);%0A%09%09serviceRequest.setConfigDescription(%22configDescription%22);%0A%09%09serviceRequest.setConfigTitle(%22configTitle%22);%0A%09%09serviceRequest.setComponentTitle(%22componentTitle%22);%0A%09%09serviceRequest.setPropertyValue(%22false%22);%0A%0A%09%09final UpdateApplicationConfigurationResponse  response = (UpdateApplicationConfigurationResponse) applicationManager.service(serviceRequest);%0A%0A%0A%09%09assertNotNull(EXPECT_A_RESULT,response);%0A%09%09assertEquals(EXPECT_SUCCESS, ServiceResult.FAILURE,response.getResult());%0A%09%7D%0A%0A
 %7D%0A

add test