blob: f35a2bb69f9e403c5e61f739f1fa3759196b2f58 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2009 Shane Clarke.
* 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:
* Shane Clarke - initial API and implementation
*******************************************************************************/
package org.eclipse.jst.ws.jaxws.core.annotation.validation.tests;
import javax.jws.WebService;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jst.ws.annotations.core.AnnotationsCore;
import org.eclipse.jst.ws.annotations.core.utils.AnnotationUtils;
import org.eclipse.jst.ws.internal.jaxws.core.JAXWSCoreMessages;
public class WebServiceWebServiceProviderCoExistRuleTest extends AbstractAnnotationValidationTest {
@Override
protected Annotation getAnnotation() {
return AnnotationsCore.createAnnotation(ast, WebService.class, WebService.class.getSimpleName(),
null);
}
@Override
protected String getClassContents() {
StringBuilder classContents = new StringBuilder("package com.example;\n\n");
classContents.append("import javax.xml.transform.Source;\n");
classContents.append("import javax.xml.ws.Provider;\n");
classContents.append("import javax.xml.ws.WebServiceProvider;\n\n");
classContents.append("@WebServiceProvider\n");
classContents.append("public class MyClass implements Provider<Source> {\n\n");
classContents.append("\tpublic Source invoke(Source arg0) {" + "\n\t\treturn null;\n\t}\n\n}");
return classContents.toString();
}
@Override
protected String getClassName() {
return "MyClass.java";
}
@Override
protected String getPackageName() {
return "com.example";
}
public void testWebServiceWebServiceProviderCoExistRule() {
try {
assertNotNull(annotation);
assertEquals(WebService.class.getSimpleName(), AnnotationUtils.getAnnotationName(annotation));
AnnotationUtils.addImportEdit(compilationUnit, WebService.class, textFileChange, true);
AnnotationUtils.addAnnotationToType(source, compilationUnit, rewriter,
source.findPrimaryType(), annotation, textFileChange);
assertTrue(executeChange(new NullProgressMonitor(), textFileChange));
assertTrue(AnnotationUtils.isAnnotationPresent(source, AnnotationUtils
.getAnnotationName(annotation)));
Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, null);
IMarker[] allmarkers = source.getResource().findMarkers(IMarker.PROBLEM, true,
IResource.DEPTH_INFINITE);
assertEquals(1, allmarkers.length);
IMarker annotationProblemMarker = allmarkers[0];
assertEquals(source.getResource(), annotationProblemMarker.getResource());
assertEquals(JAXWSCoreMessages.WEBSERVICE_WEBSERVICEPROVIDER_COMBINATION,
annotationProblemMarker.getAttribute(IMarker.MESSAGE));
} catch (CoreException ce) {
fail(ce.getLocalizedMessage());
} catch (OperationCanceledException oce) {
fail(oce.getLocalizedMessage());
} catch (InterruptedException ie) {
fail(ie.getLocalizedMessage());
}
}
}