Skip to main content
summaryrefslogtreecommitdiffstats
blob: a67b1cd97bdd39e03e4f2b66da4a4efbb09a5998 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*******************************************************************************
 * Copyright (c) 2011 Oracle. 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.
 * 
 * Contributors:
 *     Oracle - initial API and implementation
 ******************************************************************************/
package org.eclipse.jpt.jpa.eclipselink.core.tests.internal.v2_3.resource.java;

import java.util.Iterator;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
import org.eclipse.jpt.jpa.eclipselink.core.v2_3.resource.java.EclipseLink2_3;
import org.eclipse.jpt.jpa.eclipselink.core.v2_3.resource.java.EclipseLinkMultitenantAnnotation;
import org.eclipse.jpt.jpa.eclipselink.core.v2_3.resource.java.MultitenantType;

@SuppressWarnings("nls")
public class EclipselinkMultitenantAnnotationTests extends EclipseLink2_3JavaResourceModelTestCase {

	public EclipselinkMultitenantAnnotationTests(String name) {
		super(name);
	}
	
	private ICompilationUnit createTestMultitenant() throws Exception {
		return this.createTestType(new DefaultAnnotationWriter() {
			@Override
			public Iterator<String> imports() {
				return new ArrayIterator<String>(EclipseLink2_3.MULTITENANT);
			}
			@Override
			public void appendTypeAnnotationTo(StringBuilder sb) {
				sb.append("@Multitenant");
			}
		});
	}
	
	private ICompilationUnit createTestMultitenantWithValue() throws Exception {
		return this.createTestType(new DefaultAnnotationWriter() {
			@Override
			public Iterator<String> imports() {
				return new ArrayIterator<String>(EclipseLink2_3.MULTITENANT, EclipseLink2_3.MULTITENANT_TYPE);
			}
			@Override
			public void appendTypeAnnotationTo(StringBuilder sb) {
				sb.append("@Multitenant(MultitenantType.SINGLE_TABLE)");
			}
		});
	}

	public void testMultitenant() throws Exception {
		ICompilationUnit cu = this.createTestMultitenant();
		JavaResourceType resourceType = buildJavaResourceType(cu); 

		EclipseLinkMultitenantAnnotation multitenant = (EclipseLinkMultitenantAnnotation) resourceType.getAnnotation(EclipseLink2_3.MULTITENANT);
		assertNotNull(multitenant);
	}

	public void testGetValue() throws Exception {
		ICompilationUnit cu = this.createTestMultitenantWithValue();
		JavaResourceType resourceType = buildJavaResourceType(cu);
		
		EclipseLinkMultitenantAnnotation multitenant = (EclipseLinkMultitenantAnnotation) resourceType.getAnnotation(EclipseLink2_3.MULTITENANT);
		assertEquals(MultitenantType.SINGLE_TABLE, multitenant.getValue());
	}

	public void testSetValue() throws Exception {
		ICompilationUnit cu = this.createTestMultitenantWithValue();
		JavaResourceType resourceType = buildJavaResourceType(cu);
		
		EclipseLinkMultitenantAnnotation multitenant = (EclipseLinkMultitenantAnnotation) resourceType.getAnnotation(EclipseLink2_3.MULTITENANT);
		assertEquals(MultitenantType.SINGLE_TABLE, multitenant.getValue());
		
		multitenant.setValue(MultitenantType.TABLE_PER_TENANT);
		assertEquals(MultitenantType.TABLE_PER_TENANT, multitenant.getValue());
		
		assertSourceContains("@Multitenant(TABLE_PER_TENANT)", cu);
		
		multitenant.setValue(null);
		assertNull(multitenant.getValue());
		
		assertSourceDoesNotContain("(TABLE_PER_TENANT)", cu);
		assertSourceContains("@Multitenant", cu);
		assertSourceDoesNotContain("@Multitenant(", cu);
	}
}

Back to the top