blob: 231b3d1afab0b6bfa7357dd74130af9f7c74e3a9 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2011, 2013 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0, which accompanies this distribution
* and is available at https://www.eclipse.org/legal/epl-2.0/.
*
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.jpa.eclipselink.core.tests.internal.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.iterator.IteratorTools;
import org.eclipse.jpt.jpa.eclipselink.core.resource.java.EclipseLink;
@SuppressWarnings("nls")
public class EclipseLinkPrimaryKeyAnnotationTests
extends EclipseLinkJavaResourceModelTestCase
{
public EclipseLinkPrimaryKeyAnnotationTests(String name) {
super(name);
}
private ICompilationUnit createTestTypeWithPrimaryKeyAnnotation() throws Exception {
return this.createTestType(new DefaultAnnotationWriter() {
@Override
public Iterator<String> imports() {
return IteratorTools.iterator(EclipseLink.PRIMARY_KEY);
}
@Override
public void appendTypeAnnotationTo(StringBuilder sb) {
sb.append("@PrimaryKey");
}
});
}
public void testAddRemoveAnnotation() throws Exception {
ICompilationUnit cu = this.createTestTypeWithPrimaryKeyAnnotation();
JavaResourceType resourceType = buildJavaResourceType(cu);
assertNotNull(resourceType.getAnnotation(EclipseLink.PRIMARY_KEY));
resourceType.removeAnnotation(EclipseLink.PRIMARY_KEY);
assertNull(resourceType.getAnnotation(EclipseLink.PRIMARY_KEY));
resourceType.addAnnotation(EclipseLink.PRIMARY_KEY);
assertNotNull(resourceType.getAnnotation(EclipseLink.PRIMARY_KEY));
}
}