/*
 * This is part of Geomajas, a GIS framework, http://www.geomajas.org/.
 *
 * Copyright 2008-2015 Geosparc nv, http://www.geosparc.com/, Belgium.
 *
 * The program is available in open source according to the GNU Affero
 * General Public License. All contributions in this program are covered
 * by the Geomajas Contributors License Agreement. For full licensing
 * details, see LICENSE.txt in the project root.
 */

package org.geomajas.internal.layer.feature;

import org.geomajas.layer.VectorLayer;
import org.geomajas.layer.feature.Attribute;
import org.geomajas.layer.feature.InternalFeature;
import org.geomajas.spring.ThreadScopeContextHolder;
import org.geomajas.testdata.Country;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.fest.assertions.Assertions.assertThat;

/**
 * Test for AttributeService.
 *
 * @author Joachim Van der Auwera
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/org/geomajas/spring/geomajasContext.xml",
		"/org/geomajas/testdata/beanContext.xml", "/org/geomajas/testdata/layerBeans.xml",
		"/org/geomajas/internal/service/countriesNotAllEditable.xml"})
public class AttributeServiceEditableCapabilityTest {

	private static final long TEST_ID = 17;
	private static final String TEST_COUNTRY = "BE";
	private static final String TEST_NAME = "Belgium";

	private Country bean;

	@Autowired
	@Qualifier("layerCountriesNotAllEditable")
	private VectorLayer layer;

	@Autowired
	private AttributeService attributeService;

	@Autowired
	private org.geomajas.security.SecurityManager securityManager;

	@Before
	public void init() {
		bean = new Country();
		bean.setId(TEST_ID);
		bean.setCountry(TEST_COUNTRY);
		bean.setName(TEST_NAME);
		securityManager.createSecurityContext(""); // log in
	}

	@After
	public void fixSideEffects() {
		ThreadScopeContextHolder.clear();
	}

	@Test
	public void testEditableState() throws Exception {
		InternalFeature feature = new InternalFeatureImpl();
		Assert.assertNotNull(attributeService.getAttributes(layer, feature, bean));
		Attribute attribute;
		Attribute linked;
		attribute = feature.getAttributes().get("country");
		assertThat(attribute.getValue()).isEqualTo(TEST_COUNTRY);
		assertThat(attribute.isEditable()).isFalse(); // AllowAll + editable==false -> not editable
		attribute = feature.getAttributes().get("name");
		assertThat(attribute.getValue()).isEqualTo(TEST_NAME);
		assertThat(attribute.isEditable()).isTrue(); // AllowAll + editable=true -> editable
	}

}


@@ -685,16 +685,125 @@
 ountry;%0A
+import org.geomajas.testdata.ReloadContext;%0Aimport org.geomajas.testdata.ReloadContextTestExecutionListener;%0A
 import o
@@ -814,24 +814,24 @@
 unit.After;%0A
-
 import org.j
@@ -1112,16 +1112,80 @@
 ration;%0A
+import org.springframework.test.context.TestExecutionListeners;%0A
 import o
@@ -1247,16 +1247,106 @@
 sRunner;
+%0Aimport org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
 %0A%0Aimport
@@ -1672,24 +1672,24 @@
 Beans.xml%22,%0A
-
 %09%09%22/org/geom
@@ -1741,16 +1741,161 @@
 .xml%22%7D)%0A
+@TestExecutionListeners(listeners = %7BReloadContextTestExecutionListener.class,%0A%09%09DependencyInjectionTestExecutionListener.class%7D)%0A@ReloadContext%0A
 public c

test fails on travis