configtool/com.nokia.S60CT.validation/tst/src/testCase/AbstractConstraintTest.java
author terytkon
Thu, 11 Mar 2010 18:39:02 +0200
changeset 0 30eb2d538f02
permissions -rw-r--r--
Moved all configtools under oss repository and under epl licence.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
     1
/*
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
     3
* All rights reserved.
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
     4
* This component and the accompanying materials are made available
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
     6
* which accompanies this distribution, and is available
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
     8
*
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
     9
* Initial Contributors:
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    11
*
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    12
* Contributors:
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    13
*
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    14
* Description:
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    15
*
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    16
*/
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    17
package testCase;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    18
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    19
import java.util.Collection;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    20
import java.util.List;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    21
import java.util.Set;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    22
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    23
import junit.framework.TestCase;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    24
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    25
import org.eclipse.core.runtime.IStatus;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    26
import org.eclipse.core.runtime.Status;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    27
import org.eclipse.emf.ecore.EObject;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    28
import org.eclipse.emf.ecore.EStructuralFeature;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    29
import org.eclipse.emf.validation.AbstractModelConstraint;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    30
import org.eclipse.emf.validation.EMFEventType;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    31
import org.eclipse.emf.validation.IValidationContext;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    32
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    33
public abstract class AbstractConstraintTest extends TestCase {
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    34
	protected AbstractModelConstraint constraint = null;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    35
	protected ValidationContext ctx = new ValidationContext();
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    36
	
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    37
	protected abstract void setUp() throws Exception;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    38
	
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    39
	protected void tearDown() throws Exception {
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    40
		super.tearDown();
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    41
		constraint = null;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    42
	}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    43
	
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    44
	protected abstract Pair[] getAcceptedObjects();
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    45
	protected abstract Pair[] getRejectedObjects();
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    46
	
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    47
	public void testAcceptedObjects(){
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    48
		assertNotNull("Constraint is not defined.", constraint);
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    49
		Pair[] acceptedPairs = getAcceptedObjects();
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    50
		assertNotNull("No accepted objects", acceptedPairs);
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    51
		for(Pair pair : acceptedPairs){
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    52
			ctx.setTarget(pair.getObject());
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    53
			IStatus status = constraint.validate(ctx);
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    54
			assertEquals(pair.getMsg(), IStatus.OK, status.getSeverity());
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    55
		}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    56
	}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    57
	
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    58
	public void testRejectedObjects(){
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    59
		assertNotNull("Constraint is not defined.", constraint);
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    60
		Pair[] rejectedPairs = getRejectedObjects();
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    61
		assertNotNull("No rejected objects", rejectedPairs);
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    62
		for(Pair pair : rejectedPairs){
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    63
			ctx.setTarget(pair.getObject());
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    64
			IStatus status = constraint.validate(ctx);
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    65
			assertEquals(pair.getMsg(), IStatus.ERROR, status.getSeverity());
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    66
		}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    67
	}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    68
	
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    69
	protected class Pair{
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    70
		private EObject obj=null;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    71
		private String msg=null;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    72
		public Pair(EObject obj, String msg){
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    73
			this.obj=obj;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    74
			this.msg=msg;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    75
		}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    76
		public EObject getObject(){
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    77
			return obj;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    78
		}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    79
		public String getMsg(){
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    80
			return msg;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    81
		}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    82
	}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    83
	
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    84
	private class ValidationContext implements IValidationContext {
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    85
		Status failtureStatus = new Status(IStatus.ERROR,"id","");
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    86
		Status successStatus = new Status(IStatus.OK,"id","");
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    87
		EObject target = null;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    88
		
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    89
		@Override
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    90
		public void addResult(EObject object) {
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    91
			
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    92
		}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    93
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    94
		@Override
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    95
		public void addResults(Collection objects) {
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    96
			
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    97
		}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    98
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
    99
		@Override
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   100
		public IStatus createFailureStatus(Object[] messageArguments) {
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   101
			return failtureStatus;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   102
		}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   103
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   104
		@Override
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   105
		public IStatus createSuccessStatus() {
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   106
			return successStatus;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   107
		}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   108
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   109
		@Override
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   110
		public void disableCurrentConstraint(Throwable exception) {
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   111
			
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   112
		}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   113
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   114
		@Override
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   115
		public List getAllEvents() {
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   116
			return null;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   117
		}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   118
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   119
		@Override
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   120
		public Object getCurrentConstraintData() {
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   121
			return null;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   122
		}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   123
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   124
		@Override
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   125
		public String getCurrentConstraintId() {
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   126
			return null;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   127
		}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   128
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   129
		@Override
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   130
		public EMFEventType getEventType() {
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   131
			return null;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   132
		}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   133
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   134
		@Override
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   135
		public EStructuralFeature getFeature() {
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   136
			return null;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   137
		}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   138
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   139
		@Override
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   140
		public Object getFeatureNewValue() {
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   141
			return null;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   142
		}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   143
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   144
		@Override
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   145
		public Set getResultLocus() {
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   146
			return null;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   147
		}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   148
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   149
		@Override
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   150
		public EObject getTarget() {
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   151
			return target;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   152
		}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   153
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   154
		public void setTarget(EObject target){
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   155
			this.target = target;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   156
		}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   157
		
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   158
		@Override
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   159
		public Object putCurrentConstraintData(Object newData) {
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   160
			return null;
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   161
		}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   162
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   163
		@Override
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   164
		public void skipCurrentConstraintFor(EObject object) {
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   165
			
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   166
		}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   167
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   168
		@Override
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   169
		public void skipCurrentConstraintForAll(Collection objects) {
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   170
			
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   171
		}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   172
		
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   173
	}
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   174
	
30eb2d538f02 Moved all configtools under oss repository and under epl licence.
terytkon
parents:
diff changeset
   175
}