/* Copyright (C) 2008-2009 by Claas Wilke (claaswilke@gmx.net) This file is part of the OCL2 Parser Test Suite of Dresden OCL2 for Eclipse. Dresden OCL2 for Eclipse 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, either version 3 of the License, or (at your option) any later version. Dresden OCL2 for Eclipse 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. You should have received a copy of the GNU Lesser General Public License along with Dresden OCL2 for Eclipse. If not, see <http://www.gnu.org/licenses/>. */ package org.dresdenocl.ocl2parser.test.expressions; import static org.junit.Assert.fail; import java.io.FileNotFoundException; import org.junit.Test; import org.dresdenocl.model.ModelAccessException; import org.dresdenocl.ocl2parser.test.TestPerformer; import org.dresdenocl.ocl2parser.test.exception.MetaModelNotFoundException; import org.dresdenocl.parser.ParseException; /** * <p> * Contains test cases that check that IfExpressions are parsed appropriately. * </p> * * @author Claas Wilke */ public class TestIfExpressions { /** * <p> * A test case to check that a IfExpression is parsed appropriately. * </p> */ @Test public void testIfPositive01() throws Exception { TestPerformer testPerformer; String modelFileName; String oclFileName; oclFileName = "expressions/ifPositive01.ocl"; modelFileName = "testmodel.uml"; /* Try to get the TestPerformer. */ try { testPerformer = TestPerformer.getInstance( AllExpressionTests.META_MODEL_ID, AllExpressionTests.MODEL_BUNDLE, AllExpressionTests.MODEL_DIRECTORY); testPerformer.setModel(modelFileName); /* Try to parse the constraint file. */ try { testPerformer.parseFile(oclFileName); } catch (FileNotFoundException e) { fail("Failed to parse File. Reason: " + e.getMessage()); } // end catch. } // end try. catch (MetaModelNotFoundException e) { fail("Unable to get TestPerformer. Reason: " + e.getMessage()); } catch (FileNotFoundException e) { fail("Lacking file resources. Reason: " + e.getMessage()); } catch (ModelAccessException e) { fail("Couldn't set Model. Reason: " + e.getMessage()); } // end catch. } /** * <p> * A test case to check that a CollectionLiteralExpression is not parsed * appropriately. * </p> */ @Test(expected = ParseException.class) public void testIfNegative01() throws Exception { TestPerformer testPerformer; String modelFileName; String oclFileName; oclFileName = "expressions/ifNegative01.ocl"; modelFileName = "testmodel.uml"; /* Try to get the TestPerformer. */ testPerformer = TestPerformer.getInstance( AllExpressionTests.META_MODEL_ID, AllExpressionTests.MODEL_BUNDLE, AllExpressionTests.MODEL_DIRECTORY); testPerformer.setModel(modelFileName); /* Try to parse the constraint file. */ testPerformer.parseFile(oclFileName); } /** * <p> * A test case to check that a CollectionLiteralExpression is not parsed * appropriately. * </p> */ @Test(expected = ParseException.class) public void testIfNegative02() throws Exception { TestPerformer testPerformer; String modelFileName; String oclFileName; oclFileName = "expressions/ifNegative02.ocl"; modelFileName = "testmodel.uml"; /* Try to get the TestPerformer. */ testPerformer = TestPerformer.getInstance( AllExpressionTests.META_MODEL_ID, AllExpressionTests.MODEL_BUNDLE, AllExpressionTests.MODEL_DIRECTORY); testPerformer.setModel(modelFileName); /* Try to parse the constraint file. */ testPerformer.parseFile(oclFileName); } }