From 61315a2a9ba254d30d393a91f46df7c44c24efba Mon Sep 17 00:00:00 2001 From: Rene Schneider Date: Wed, 1 Jun 2016 12:49:18 +0200 Subject: [PATCH 1/2] fixes issue #110: Jumping to test/call/suite via URLs jumps to suitedef --- .../linking/DefaultIntegrityURLResolver.java | 48 ++++++++++++++----- .../ui/search/DefaultIntegritySearch.java | 7 +-- .../integrity/ui/search/IntegritySearch.java | 4 +- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/de.gebit.integrity.dsl.ui/src/de/gebit/integrity/ui/linking/DefaultIntegrityURLResolver.java b/de.gebit.integrity.dsl.ui/src/de/gebit/integrity/ui/linking/DefaultIntegrityURLResolver.java index 11a63b209..9bf15c42a 100644 --- a/de.gebit.integrity.dsl.ui/src/de/gebit/integrity/ui/linking/DefaultIntegrityURLResolver.java +++ b/de.gebit.integrity.dsl.ui/src/de/gebit/integrity/ui/linking/DefaultIntegrityURLResolver.java @@ -10,6 +10,10 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; @@ -46,11 +50,12 @@ public boolean parseURL(String anURL) { Matcher tempMatcher = INTEGRITY_URL_PATTERN.matcher(anURL); if (tempMatcher.matches()) { String tempSuiteName = tempMatcher.group(1); - IEditorPart tempEditor = integritySearch.openSuiteDefinitionByName(tempSuiteName); + boolean tempHasLineNumber = tempMatcher.groupCount() > 1 && tempMatcher.group(2) != null; + IEditorPart tempEditor = integritySearch.openSuiteDefinitionByName(tempSuiteName, !tempHasLineNumber); if (tempEditor == null) { showError("Could not find a suite named '" + tempSuiteName + "' in your workspace."); } else { - if (tempMatcher.groupCount() > 1) { + if (tempHasLineNumber) { int tempLineNumber = Integer.parseInt(tempMatcher.group(2)); if (!jumpToLine(tempEditor, tempLineNumber)) { showError("Could not find line number " + tempLineNumber + " in suite '" + tempSuiteName + "'"); @@ -78,19 +83,40 @@ private boolean jumpToLine(IEditorPart anEditor, int aLineNumber) { if (!(anEditor instanceof ITextEditor) || aLineNumber <= 0) { return false; } - ITextEditor tempEditor = (ITextEditor) anEditor; + final ITextEditor tempEditor = (ITextEditor) anEditor; IDocument tempDocument = tempEditor.getDocumentProvider().getDocument(tempEditor.getEditorInput()); if (tempDocument != null) { - IRegion tempLineInfo = null; try { - tempLineInfo = tempDocument.getLineInformation(aLineNumber - 1); + final IRegion tempLineInfo = tempDocument.getLineInformation(aLineNumber - 1); + + if (tempLineInfo != null) { + // This is performed asynchronously because Xtext does it in the same way since 2.8 or so. + // The Xtext change originally caused issue #110: Jumping to test/call/suite invocations via + // integrity:// URLs jumps to suitedef instead + Job selectAndRevealJob = new Job("Select and reveal line " + aLineNumber) { + @Override + protected IStatus run(IProgressMonitor monitor) { + tempEditor.getSite().getWorkbenchWindow().getWorkbench().getDisplay() + .asyncExec(new Runnable() { + @Override + public void run() { + tempEditor.selectAndReveal(tempLineInfo.getOffset(), + tempLineInfo.getLength()); + + } + }); + return Status.OK_STATUS; + } + }; + selectAndRevealJob.setSystem(true); + selectAndRevealJob.setPriority(Job.SHORT); + selectAndRevealJob.schedule(); + + return true; + } else { + return false; + } } catch (BadLocationException exc) { - // ignored - } - if (tempLineInfo != null) { - tempEditor.selectAndReveal(tempLineInfo.getOffset(), tempLineInfo.getLength()); - return true; - } else { return false; } } diff --git a/de.gebit.integrity.dsl.ui/src/de/gebit/integrity/ui/search/DefaultIntegritySearch.java b/de.gebit.integrity.dsl.ui/src/de/gebit/integrity/ui/search/DefaultIntegritySearch.java index 66e770f46..52b1ad4a2 100644 --- a/de.gebit.integrity.dsl.ui/src/de/gebit/integrity/ui/search/DefaultIntegritySearch.java +++ b/de.gebit.integrity.dsl.ui/src/de/gebit/integrity/ui/search/DefaultIntegritySearch.java @@ -45,7 +45,8 @@ public class DefaultIntegritySearch implements IntegritySearch { public SuiteDefinition[] findSuiteDefinitionByName(String aSuiteName) { List tempResult = new ArrayList(); - for (IEObjectDescription tempDesc : searchEngine.findMatches(aSuiteName, SuiteDefinition.class.getSimpleName())) { + for (IEObjectDescription tempDesc : searchEngine.findMatches(aSuiteName, + SuiteDefinition.class.getSimpleName())) { EObject tempObject = tempDesc.getEObjectOrProxy(); if (tempObject instanceof SuiteDefinition) { SuiteDefinition tempDefinition = (SuiteDefinition) tempObject; @@ -61,10 +62,10 @@ public SuiteDefinition[] findSuiteDefinitionByName(String aSuiteName) { } @Override - public IEditorPart openSuiteDefinitionByName(String aSuiteName) { + public IEditorPart openSuiteDefinitionByName(String aSuiteName, boolean aSelectFlag) { SuiteDefinition[] tempSuiteDef = findSuiteDefinitionByName(aSuiteName); if (tempSuiteDef != null) { - return uriEditorOpener.open(EcoreUtil.getURI(tempSuiteDef[0]), true); + return uriEditorOpener.open(EcoreUtil.getURI(tempSuiteDef[0]), aSelectFlag); } else { return null; } diff --git a/de.gebit.integrity.dsl.ui/src/de/gebit/integrity/ui/search/IntegritySearch.java b/de.gebit.integrity.dsl.ui/src/de/gebit/integrity/ui/search/IntegritySearch.java index 66f72adf1..36b0e6da1 100644 --- a/de.gebit.integrity.dsl.ui/src/de/gebit/integrity/ui/search/IntegritySearch.java +++ b/de.gebit.integrity.dsl.ui/src/de/gebit/integrity/ui/search/IntegritySearch.java @@ -34,8 +34,10 @@ public interface IntegritySearch { * * @param aSuiteName * the suite name to open (or part of) + * @param aSelectFlag + * whether the suite name shall be jumped to and selected * @return the opened editor or null */ - IEditorPart openSuiteDefinitionByName(String aSuiteName); + IEditorPart openSuiteDefinitionByName(String aSuiteName, boolean aSelectFlag); } From 6d025aef50ded1495eeb6773f77bd7bba1dc007d Mon Sep 17 00:00:00 2001 From: Rene Schneider Date: Wed, 1 Jun 2016 13:34:47 +0200 Subject: [PATCH 2/2] fixed #109: ObjectToMap conversion ignores transient properties --- .../conversions/java/other/ObjectToMap.java | 24 ++ .../integrity/fixtures/BeanFixture.integrity | 63 ++-- .../beans/beanWithTransientProperty.integrity | 18 ++ .../beans/BeanWithTransientProperty.java | 43 +++ ....basic.beans.beanWithTransientProperty.xml | 34 +++ .../fixtures/basic/beans/BeanFixture.java | 283 +++++++++--------- .../basic/beans/TransientTestBean.java | 36 +++ 7 files changed, 332 insertions(+), 169 deletions(-) create mode 100644 de.gebit.integrity.tests/integrity/suites/basic/beans/beanWithTransientProperty.integrity create mode 100644 de.gebit.integrity.tests/junit/de/gebit/integrity/tests/junit/basic/beans/BeanWithTransientProperty.java create mode 100644 de.gebit.integrity.tests/results/integrity.basic.beans.beanWithTransientProperty.xml create mode 100644 de.gebit.integrity.tests/src/de/gebit/integrity/tests/fixtures/basic/beans/TransientTestBean.java diff --git a/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/java/other/ObjectToMap.java b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/java/other/ObjectToMap.java index 2ef31009f..734a311ed 100644 --- a/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/java/other/ObjectToMap.java +++ b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/java/other/ObjectToMap.java @@ -44,6 +44,15 @@ public Map convert(Object aSource, Class aTargetType, ConversionC try { for (PropertyDescriptor tempDescriptor : Introspector.getBeanInfo(aSource.getClass(), Object.class) .getPropertyDescriptors()) { + + if (Boolean.TRUE.equals(tempDescriptor.getValue("transient"))) { + // Skip transient properties, as those are often used as "fake" properties in order to implement a + // getter for them which does some sort of magic. Calling unknown magical stuff in a generic fashion + // when running over Java Beans is not such a good idea and quickly leads to problems, which is the + // reason why transient properties are skipped here. See also issue #109. + continue; + } + Method tempReadMethod = tempDescriptor.getReadMethod(); if (tempReadMethod != null) { Object tempValue = tempReadMethod.invoke(aSource); @@ -83,4 +92,19 @@ public Map convert(Object aSource, Class aTargetType, ConversionC return tempKeyValueMap; } + + // protected boolean isTransient(String aFieldName, Class aClass) { + // Class tempClassInFocus = aClass; + // while(tempClassInFocus != null) { + // try { + // Field tempField = tempClassInFocus.getDeclaredField(aFieldName); + // + // if(tempField != null) { + // return tempField.getModifiers() & Modifier + // } + // } catch (NoSuchFieldException | SecurityException exc) { + // // ignore + // } + // } + // } } diff --git a/de.gebit.integrity.tests/integrity/fixtures/BeanFixture.integrity b/de.gebit.integrity.tests/integrity/fixtures/BeanFixture.integrity index 25ea39361..67a4d660b 100644 --- a/de.gebit.integrity.tests/integrity/fixtures/BeanFixture.integrity +++ b/de.gebit.integrity.tests/integrity/fixtures/BeanFixture.integrity @@ -1,31 +1,34 @@ -packagedef integrity.fixtures.basic.beans with - - testdef checkSimpleBean uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#checkSimpleBean - - testdef checkCollectionBean uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#checkCollectionBean - - testdef alterPrimitiveBean uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#alterPrimitiveBean - - testdef checkSimpleBeanUntyped uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#checkSimpleBeanUntyped - - testdef createSimpleBeanUntyped uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#createSimpleBeanUntyped - calldef createSimpleBeanUntypedCall uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#createSimpleBeanUntyped - - testdef createMapForSimpleBeanUntyped uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#createMapForSimpleBeanUntyped - calldef createMapForSimpleBeanUntypedCall uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#createMapForSimpleBeanUntyped - - testdef echoEnumTestBean uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#echoEnumTestBean - calldef echoEnumTestBeanCall uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#echoEnumTestBean - - testdef echoEnumValueFromTestBean uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#echoEnumValueFromTestBean - calldef echoEnumValueFromTestBeanCall uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#echoEnumValueFromTestBean - - testdef echoMap uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#echoMap - calldef echoMapCall uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#echoMap - - calldef createPrimitiveTypeArrayTestBean uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#createPrimitiveTypeArrayTestBean - - testdef createSimpleBeanUntypedEmpty uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#createSimpleBeanUntypedEmpty - calldef createSimpleBeanUntypedEmptyCall uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#createSimpleBeanUntypedEmpty - +packagedef integrity.fixtures.basic.beans with + + testdef checkSimpleBean uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#checkSimpleBean + + testdef checkCollectionBean uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#checkCollectionBean + + testdef alterPrimitiveBean uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#alterPrimitiveBean + + testdef checkSimpleBeanUntyped uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#checkSimpleBeanUntyped + + testdef createSimpleBeanUntyped uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#createSimpleBeanUntyped + calldef createSimpleBeanUntypedCall uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#createSimpleBeanUntyped + + testdef createMapForSimpleBeanUntyped uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#createMapForSimpleBeanUntyped + calldef createMapForSimpleBeanUntypedCall uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#createMapForSimpleBeanUntyped + + testdef echoEnumTestBean uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#echoEnumTestBean + calldef echoEnumTestBeanCall uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#echoEnumTestBean + + testdef echoEnumValueFromTestBean uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#echoEnumValueFromTestBean + calldef echoEnumValueFromTestBeanCall uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#echoEnumValueFromTestBean + + testdef echoMap uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#echoMap + calldef echoMapCall uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#echoMap + + calldef createPrimitiveTypeArrayTestBean uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#createPrimitiveTypeArrayTestBean + + testdef createSimpleBeanUntypedEmpty uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#createSimpleBeanUntypedEmpty + calldef createSimpleBeanUntypedEmptyCall uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#createSimpleBeanUntypedEmpty + + testdef createTransientTestBean uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#createTransientTestBean + calldef createTransientTestBeanCall uses de.gebit.integrity.tests.fixtures.basic.beans.BeanFixture#createTransientTestBean + packageend \ No newline at end of file diff --git a/de.gebit.integrity.tests/integrity/suites/basic/beans/beanWithTransientProperty.integrity b/de.gebit.integrity.tests/integrity/suites/basic/beans/beanWithTransientProperty.integrity new file mode 100644 index 000000000..7d59b0e68 --- /dev/null +++ b/de.gebit.integrity.tests/integrity/suites/basic/beans/beanWithTransientProperty.integrity @@ -0,0 +1,18 @@ +packagedef integrity.basic.beans with + + suitedef beanWithTransientProperty with + + // This should succeed, since we don't check the transient property + test integrity.fixtures.basic.beans.createTransientTestBean = { + normalString: "foo" + } + + // This should fail as we cannot see the transient property here since it's not converted to the map internally + test integrity.fixtures.basic.beans.createTransientTestBean = { + normalString: "foo" + transientString: "bar" + } + + suiteend + +packageend \ No newline at end of file diff --git a/de.gebit.integrity.tests/junit/de/gebit/integrity/tests/junit/basic/beans/BeanWithTransientProperty.java b/de.gebit.integrity.tests/junit/de/gebit/integrity/tests/junit/basic/beans/BeanWithTransientProperty.java new file mode 100644 index 000000000..22dcba751 --- /dev/null +++ b/de.gebit.integrity.tests/junit/de/gebit/integrity/tests/junit/basic/beans/BeanWithTransientProperty.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package de.gebit.integrity.tests.junit.basic.beans; + +import java.io.IOException; + +import org.jdom.Document; +import org.jdom.JDOMException; +import org.junit.Test; + +import de.gebit.integrity.runner.exceptions.ModelLoadException; +import de.gebit.integrity.tests.junit.IntegrityJUnitTest; + +/** + * JUnit test which checks bean calls. + * + * + * @author Rene Schneider - initial API and implementation + * + */ +public class BeanWithTransientProperty extends IntegrityJUnitTest { + + /** + * Performs a suite which does fixture calls with bean values and checks the resulting XML document. + * + * @throws ModelLoadException + * @throws IOException + * @throws JDOMException + */ + @Test + public void test() throws ModelLoadException, IOException, JDOMException { + Document tempResult = executeIntegritySuite( + new String[] { "integrity/suites/basic/beans/beanWithTransientProperty.integrity" }, + "integrity.basic.beans.beanWithTransientProperty", null); + assertDocumentMatchesReference(tempResult); + } + +} diff --git a/de.gebit.integrity.tests/results/integrity.basic.beans.beanWithTransientProperty.xml b/de.gebit.integrity.tests/results/integrity.basic.beans.beanWithTransientProperty.xml new file mode 100644 index 000000000..0dfa803a7 --- /dev/null +++ b/de.gebit.integrity.tests/results/integrity.basic.beans.beanWithTransientProperty.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/de.gebit.integrity.tests/src/de/gebit/integrity/tests/fixtures/basic/beans/BeanFixture.java b/de.gebit.integrity.tests/src/de/gebit/integrity/tests/fixtures/basic/beans/BeanFixture.java index 3c918de66..d5b8d90e8 100644 --- a/de.gebit.integrity.tests/src/de/gebit/integrity/tests/fixtures/basic/beans/BeanFixture.java +++ b/de.gebit.integrity.tests/src/de/gebit/integrity/tests/fixtures/basic/beans/BeanFixture.java @@ -1,139 +1,144 @@ -/******************************************************************************* - * Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package de.gebit.integrity.tests.fixtures.basic.beans; - -import java.math.BigDecimal; -import java.util.HashMap; -import java.util.Map; - -import de.gebit.integrity.fixtures.FixtureMethod; -import de.gebit.integrity.fixtures.FixtureParameter; -import de.gebit.integrity.tests.fixtures.basic.beans.CollectionTestBean.InnerBean; -import de.gebit.integrity.tests.fixtures.basic.beans.EnumTestBean.InnerEnum; - -//SUPPRESS CHECKSTYLE LONG Javadoc -public class BeanFixture { - - @FixtureMethod(description = "checks the bean $bean$") - public boolean checkSimpleBean(@FixtureParameter(name = "bean") SimpleTestBean aBean) { - return "string".equals(aBean.getFirstParameter()) && aBean.getSecondParameter() == 100 - && aBean.getThirdParameter().getInnerParameter().equals(new BigDecimal("1.99")); - } - - @FixtureMethod(description = "gets the bean $bean$ and counts all entries in all lists") - public int checkCollectionBean(@FixtureParameter(name = "bean") CollectionTestBean aBean) { - int tempCount = 0; - if (aBean.getArrayParameter() != null) { - tempCount += aBean.getArrayParameter().length; - } - if (aBean.getParameterizedListParameter() != null) { - // Verify these are of the right type by casting - for (@SuppressWarnings("unused") - Integer tempElement : aBean.getParameterizedListParameter()) { - tempCount++; - } - } - if (aBean.getPlainCollectionParameter() != null) { - tempCount += aBean.getPlainCollectionParameter().size(); - } - if (aBean.getPlainListParameter() != null) { - tempCount += aBean.getPlainListParameter().size(); - } - if (aBean.getSetParameterWithInnerBean() != null) { - // Verify these are of the right type by casting - for (@SuppressWarnings("unused") - InnerBean tempElement : aBean.getSetParameterWithInnerBean()) { - tempCount++; - } - } - if (aBean.getLowerBoundParameterizedListParameter() != null) { - // Verify these are of the right type by casting - for (@SuppressWarnings("unused") - Integer tempElement : aBean.getLowerBoundParameterizedListParameter()) { - tempCount++; - } - } - - return tempCount; - } - - @FixtureMethod(description = "takes the bean $bean$, alters it a little bit and returns it") - public PrimitiveTypeTestBean alterPrimitiveBean(@FixtureParameter(name = "bean") PrimitiveTypeTestBean aBean) { - aBean.alterABit(); - return aBean; - } - - @FixtureMethod(description = "checks the bean $bean$") - public boolean checkSimpleBeanUntyped(@FixtureParameter(name = "bean") Object aBean) { - SimpleTestBean tempBean = (SimpleTestBean) aBean; - - return "string".equals(tempBean.getFirstParameter()) && tempBean.getSecondParameter() == 100 - && tempBean.getThirdParameter().getInnerParameter().equals(new BigDecimal("1.99")); - } - - @FixtureMethod(description = "creates a bean with predefined values and returns it") - public Object createSimpleBeanUntyped() { - SimpleTestBean tempBean = new SimpleTestBean(); - tempBean.setFirstParameter("string"); - tempBean.setSecondParameter(100); - SimpleTestBean.InnerBean tempInnerBean = new SimpleTestBean.InnerBean(); - tempInnerBean.setInnerParameter(new BigDecimal("1.99")); - tempBean.setThirdParameter(tempInnerBean); - - return tempBean; - } - - @FixtureMethod(description = "creates a map with some key-value pairs in it and returns it") - public Map createMapForSimpleBeanUntyped() { - Map tempOuterMap = new HashMap(); - tempOuterMap.put("firstParameter", "string"); - tempOuterMap.put("secondParameter", 100); - Map tempInnerMap = new HashMap(); - tempInnerMap.put("innerParameter", new BigDecimal("1.99")); - tempOuterMap.put("thirdParameter", tempInnerMap); - - return tempOuterMap; - } - - @FixtureMethod(description = "echoes the provided enum test bean") - public EnumTestBean echoEnumTestBean(@FixtureParameter(name = "bean") EnumTestBean aTestBean) { - return aTestBean; - } - - @FixtureMethod(description = "echoes the enum value from the provided enum test bean") - public InnerEnum echoEnumValueFromTestBean(@FixtureParameter(name = "bean") EnumTestBean aTestBean) { - return aTestBean.getEnumValue(); - } - - @FixtureMethod(description = "echoes the input as a map converted by Integrity") - public Map echoMap(@FixtureParameter(name = "bean") Map aBean) { - return aBean; - } - - @FixtureMethod(description = "creates an instance of PrimitiveTypeArrayTestBean") - public PrimitiveTypeArrayTestBean createPrimitiveTypeArrayTestBean() { - PrimitiveTypeArrayTestBean tempBean = new PrimitiveTypeArrayTestBean(); - tempBean.setPrimitiveBoolean(new boolean[] { true, false }); - tempBean.setPrimitiveByte(new byte[] { 1, 2, 3 }); - tempBean.setPrimitiveChar(new char[] { 'a', 'b', 'c' }); - tempBean.setPrimitiveDouble(new double[] { 1.0, 1.1, 1.2 }); - tempBean.setPrimitiveFloat(new float[] { 1.0f, 1.1f, 1.2f }); - tempBean.setPrimitiveInt(new int[] { 1, 2, 3 }); - tempBean.setPrimitiveLong(new long[] { 1, 2, 3 }); - tempBean.setPrimitiveShort(new short[] { 1, 2, 3 }); - - return tempBean; - } - - @FixtureMethod(description = "creates an empty bean and returns it") - public Object createSimpleBeanUntypedEmpty() { - SimpleTestBean tempBean = new SimpleTestBean(); - - return tempBean; - } -} +/******************************************************************************* + * Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package de.gebit.integrity.tests.fixtures.basic.beans; + +import java.math.BigDecimal; +import java.util.HashMap; +import java.util.Map; + +import de.gebit.integrity.fixtures.FixtureMethod; +import de.gebit.integrity.fixtures.FixtureParameter; +import de.gebit.integrity.tests.fixtures.basic.beans.CollectionTestBean.InnerBean; +import de.gebit.integrity.tests.fixtures.basic.beans.EnumTestBean.InnerEnum; + +//SUPPRESS CHECKSTYLE LONG Javadoc +public class BeanFixture { + + @FixtureMethod(description = "checks the bean $bean$") + public boolean checkSimpleBean(@FixtureParameter(name = "bean") SimpleTestBean aBean) { + return "string".equals(aBean.getFirstParameter()) && aBean.getSecondParameter() == 100 + && aBean.getThirdParameter().getInnerParameter().equals(new BigDecimal("1.99")); + } + + @FixtureMethod(description = "gets the bean $bean$ and counts all entries in all lists") + public int checkCollectionBean(@FixtureParameter(name = "bean") CollectionTestBean aBean) { + int tempCount = 0; + if (aBean.getArrayParameter() != null) { + tempCount += aBean.getArrayParameter().length; + } + if (aBean.getParameterizedListParameter() != null) { + // Verify these are of the right type by casting + for (@SuppressWarnings("unused") + Integer tempElement : aBean.getParameterizedListParameter()) { + tempCount++; + } + } + if (aBean.getPlainCollectionParameter() != null) { + tempCount += aBean.getPlainCollectionParameter().size(); + } + if (aBean.getPlainListParameter() != null) { + tempCount += aBean.getPlainListParameter().size(); + } + if (aBean.getSetParameterWithInnerBean() != null) { + // Verify these are of the right type by casting + for (@SuppressWarnings("unused") + InnerBean tempElement : aBean.getSetParameterWithInnerBean()) { + tempCount++; + } + } + if (aBean.getLowerBoundParameterizedListParameter() != null) { + // Verify these are of the right type by casting + for (@SuppressWarnings("unused") + Integer tempElement : aBean.getLowerBoundParameterizedListParameter()) { + tempCount++; + } + } + + return tempCount; + } + + @FixtureMethod(description = "takes the bean $bean$, alters it a little bit and returns it") + public PrimitiveTypeTestBean alterPrimitiveBean(@FixtureParameter(name = "bean") PrimitiveTypeTestBean aBean) { + aBean.alterABit(); + return aBean; + } + + @FixtureMethod(description = "checks the bean $bean$") + public boolean checkSimpleBeanUntyped(@FixtureParameter(name = "bean") Object aBean) { + SimpleTestBean tempBean = (SimpleTestBean) aBean; + + return "string".equals(tempBean.getFirstParameter()) && tempBean.getSecondParameter() == 100 + && tempBean.getThirdParameter().getInnerParameter().equals(new BigDecimal("1.99")); + } + + @FixtureMethod(description = "creates a bean with predefined values and returns it") + public Object createSimpleBeanUntyped() { + SimpleTestBean tempBean = new SimpleTestBean(); + tempBean.setFirstParameter("string"); + tempBean.setSecondParameter(100); + SimpleTestBean.InnerBean tempInnerBean = new SimpleTestBean.InnerBean(); + tempInnerBean.setInnerParameter(new BigDecimal("1.99")); + tempBean.setThirdParameter(tempInnerBean); + + return tempBean; + } + + @FixtureMethod(description = "creates a map with some key-value pairs in it and returns it") + public Map createMapForSimpleBeanUntyped() { + Map tempOuterMap = new HashMap(); + tempOuterMap.put("firstParameter", "string"); + tempOuterMap.put("secondParameter", 100); + Map tempInnerMap = new HashMap(); + tempInnerMap.put("innerParameter", new BigDecimal("1.99")); + tempOuterMap.put("thirdParameter", tempInnerMap); + + return tempOuterMap; + } + + @FixtureMethod(description = "echoes the provided enum test bean") + public EnumTestBean echoEnumTestBean(@FixtureParameter(name = "bean") EnumTestBean aTestBean) { + return aTestBean; + } + + @FixtureMethod(description = "echoes the enum value from the provided enum test bean") + public InnerEnum echoEnumValueFromTestBean(@FixtureParameter(name = "bean") EnumTestBean aTestBean) { + return aTestBean.getEnumValue(); + } + + @FixtureMethod(description = "echoes the input as a map converted by Integrity") + public Map echoMap(@FixtureParameter(name = "bean") Map aBean) { + return aBean; + } + + @FixtureMethod(description = "creates an instance of PrimitiveTypeArrayTestBean") + public PrimitiveTypeArrayTestBean createPrimitiveTypeArrayTestBean() { + PrimitiveTypeArrayTestBean tempBean = new PrimitiveTypeArrayTestBean(); + tempBean.setPrimitiveBoolean(new boolean[] { true, false }); + tempBean.setPrimitiveByte(new byte[] { 1, 2, 3 }); + tempBean.setPrimitiveChar(new char[] { 'a', 'b', 'c' }); + tempBean.setPrimitiveDouble(new double[] { 1.0, 1.1, 1.2 }); + tempBean.setPrimitiveFloat(new float[] { 1.0f, 1.1f, 1.2f }); + tempBean.setPrimitiveInt(new int[] { 1, 2, 3 }); + tempBean.setPrimitiveLong(new long[] { 1, 2, 3 }); + tempBean.setPrimitiveShort(new short[] { 1, 2, 3 }); + + return tempBean; + } + + @FixtureMethod(description = "creates an empty bean and returns it") + public Object createSimpleBeanUntypedEmpty() { + SimpleTestBean tempBean = new SimpleTestBean(); + + return tempBean; + } + + @FixtureMethod(description = "creates a transient test bean and returns it") + public Object createTransientTestBean() { + return new TransientTestBean(); + } +} diff --git a/de.gebit.integrity.tests/src/de/gebit/integrity/tests/fixtures/basic/beans/TransientTestBean.java b/de.gebit.integrity.tests/src/de/gebit/integrity/tests/fixtures/basic/beans/TransientTestBean.java new file mode 100644 index 000000000..1dd3c7c5f --- /dev/null +++ b/de.gebit.integrity.tests/src/de/gebit/integrity/tests/fixtures/basic/beans/TransientTestBean.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package de.gebit.integrity.tests.fixtures.basic.beans; + +import java.beans.Transient; + +//SUPPRESS CHECKSTYLE LONG Javadoc +public class TransientTestBean { + + private String normalString = "foo"; + + private String transientString = "bar"; + + public String getNormalString() { + return normalString; + } + + public void setNormalString(String aNormalString) { + this.normalString = aNormalString; + } + + @Transient + public String getTransientString() { + return transientString; + } + + public void setTransientString(String aTransientString) { + this.transientString = aTransientString; + } + +}