/* * GeoTools - The Open Source Java GIS Toolkit * http://geotools.org * * (C) 2008, Open Source Geospatial Foundation (OSGeo) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ package org.geotools.xacml.geoxacml.test; import java.io.FileInputStream; import junit.framework.Assert; import junit.framework.TestCase; import org.geotools.xacml.geoxacml.config.GeoXACML; import org.geotools.xacml.test.TestSupport; import com.sun.xacml.PDP; import com.sun.xacml.ctx.RequestCtx; import com.sun.xacml.ctx.ResponseCtx; import com.sun.xacml.ctx.Result; import com.sun.xacml.ctx.Status; /** * @author Christian Mueller * * Test for geomtry scalar functions */ public class ScalarTest extends TestCase { public ScalarTest() { super(); } public ScalarTest(String arg0) { super(arg0); } @Override protected void setUp() throws Exception { GeoXACML.initialize(); TestSupport.initOutputDir(); } public void testArea() { PDP pdp = TestSupport.getPDP(TestSupport.getGeoXACMLFNFor("scalar", "AreaPolicy.xml")); RequestCtx request = null; try { request = RequestCtx.getInstance(new FileInputStream(TestSupport.getGeoXACMLFNFor( "scalar", "AreaRequest.xml"))); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } ResponseCtx response = pdp.evaluate(request); Result result = (Result) response.getResults().iterator().next(); assertTrue(result.getDecision() == Result.DECISION_PERMIT); assertTrue(result.getStatus().getCode().iterator().next().equals(Status.STATUS_OK)); } public void testArea1() { PDP pdp = TestSupport.getPDP(TestSupport.getGeoXACMLFNFor("scalar", "AreaPolicy.xml")); RequestCtx request = null; try { request = RequestCtx.getInstance(new FileInputStream(TestSupport.getGeoXACMLFNFor( "scalar", "AreaRequest1.xml"))); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } ResponseCtx response = pdp.evaluate(request); Result result = (Result) response.getResults().iterator().next(); assertTrue(result.getDecision() == Result.DECISION_NOT_APPLICABLE); assertTrue(result.getStatus().getCode().iterator().next().equals(Status.STATUS_OK)); } public void testLength() { PDP pdp = TestSupport.getPDP(TestSupport.getGeoXACMLFNFor("scalar", "LengthPolicy.xml")); RequestCtx request = null; try { request = RequestCtx.getInstance(new FileInputStream(TestSupport.getGeoXACMLFNFor( "scalar", "LengthRequest.xml"))); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } ResponseCtx response = pdp.evaluate(request); Result result = (Result) response.getResults().iterator().next(); assertTrue(result.getDecision() == Result.DECISION_PERMIT); assertTrue(result.getStatus().getCode().iterator().next().equals(Status.STATUS_OK)); } public void testLength1() { PDP pdp = TestSupport.getPDP(TestSupport.getGeoXACMLFNFor("scalar", "LengthPolicy.xml")); RequestCtx request = null; try { request = RequestCtx.getInstance(new FileInputStream(TestSupport.getGeoXACMLFNFor( "scalar", "LengthRequest1.xml"))); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } ResponseCtx response = pdp.evaluate(request); Result result = (Result) response.getResults().iterator().next(); assertTrue(result.getDecision() == Result.DECISION_NOT_APPLICABLE); assertTrue(result.getStatus().getCode().iterator().next().equals(Status.STATUS_OK)); } public void testDistance() { PDP pdp = TestSupport.getPDP(TestSupport.getGeoXACMLFNFor("scalar", "DistancePolicy.xml")); RequestCtx request = null; try { request = RequestCtx.getInstance(new FileInputStream(TestSupport.getGeoXACMLFNFor( "scalar", "DistanceRequest.xml"))); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } ResponseCtx response = pdp.evaluate(request); Result result = (Result) response.getResults().iterator().next(); assertTrue(result.getDecision() == Result.DECISION_PERMIT); assertTrue(result.getStatus().getCode().iterator().next().equals(Status.STATUS_OK)); } public void testDistance1() { PDP pdp = TestSupport.getPDP(TestSupport.getGeoXACMLFNFor("scalar", "DistancePolicy.xml")); RequestCtx request = null; try { request = RequestCtx.getInstance(new FileInputStream(TestSupport.getGeoXACMLFNFor( "scalar", "DistanceRequest1.xml"))); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } ResponseCtx response = pdp.evaluate(request); Result result = (Result) response.getResults().iterator().next(); assertTrue(result.getDecision() == Result.DECISION_NOT_APPLICABLE); assertTrue(result.getStatus().getCode().iterator().next().equals(Status.STATUS_OK)); } public void testisWithinDistance() { PDP pdp = TestSupport.getPDP(TestSupport.getGeoXACMLFNFor("scalar", "IsWithinDistancePolicy.xml")); RequestCtx request = null; try { request = RequestCtx.getInstance(new FileInputStream(TestSupport.getGeoXACMLFNFor( "scalar", "IsWithinDistanceRequest.xml"))); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } ResponseCtx response = pdp.evaluate(request); Result result = (Result) response.getResults().iterator().next(); assertTrue(result.getDecision() == Result.DECISION_PERMIT); assertTrue(result.getStatus().getCode().iterator().next().equals(Status.STATUS_OK)); } public void testIsWithinDistance1() { PDP pdp = TestSupport.getPDP(TestSupport.getGeoXACMLFNFor("scalar", "IsWithinDistancePolicy.xml")); RequestCtx request = null; try { request = RequestCtx.getInstance(new FileInputStream(TestSupport.getGeoXACMLFNFor( "scalar", "IsWithinDistanceRequest1.xml"))); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } ResponseCtx response = pdp.evaluate(request); Result result = (Result) response.getResults().iterator().next(); assertTrue(result.getDecision() == Result.DECISION_NOT_APPLICABLE); assertTrue(result.getStatus().getCode().iterator().next().equals(Status.STATUS_OK)); } }