blob: 05b8458e73a20de79134c20d2551342926f5e53c [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.soap.SOAPBinding;
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.IMethod;
import org.eclipse.jst.ws.annotations.core.utils.AnnotationUtils;
import org.eclipse.jst.ws.internal.jaxws.core.JAXWSCoreMessages;
public class DocBareOneNonHeaderINParameterRuleTest extends AbstractDocumentBareValidationTest {
@Override
protected String getClassContents() {
StringBuilder classContents = new StringBuilder("package com.example;\n\n");
classContents.append("import javax.jws.WebParam;\n\n");
classContents.append("public class MyClass {\n\n\t");
//classContents.append("public String oneIN() {\n\t\treturn \"txt\";\n\t}\n\n\t");
classContents.append("public String oneMore(@WebParam(name=\"inOne\", mode=WebParam.Mode.IN) String ");
classContents.append("inOne, @WebParam(name=\"inTwo\", mode=WebParam.Mode.IN)String inTwo) {\n\t\t");
classContents.append("return \"txt\";\n\t}\n\n\tpublic String onlyOneIN(String inOne, String inTwo) {");
classContents.append("\n\t\treturn \"txt\";\n\t}\n}");
return classContents.toString();
}
/*
public void testOneNonHeaderINParameterRule() {
try {
assertNotNull(annotation);
assertEquals("SOAPBinding", AnnotationUtils.getAnnotationName(annotation));
IMethod method = source.findPrimaryType().getMethod("oneIN", new String[0]);
assertNotNull(method);
AnnotationUtils.getImportChange(compilationUnit, javax.jws.soap.SOAPBinding.class,
textFileChange, true);
AnnotationUtils.createMethodAnnotationChange(source, compilationUnit, rewriter, method,
annotation, textFileChange);
assertTrue(executeChange(new NullProgressMonitor(), textFileChange));
assertTrue(AnnotationUtils.isAnnotationPresent(method, 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.DOC_BARE_ONE_NON_HEADER_IN_PARAMETER_ERROR_MESSAGE,
annotationProblemMarker.getAttribute(IMarker.MESSAGE));
} catch (CoreException ce) {
fail(ce.getLocalizedMessage());
} catch (OperationCanceledException oce) {
fail(oce.getLocalizedMessage());
} catch (InterruptedException ie) {
fail(ie.getLocalizedMessage());
}
}*/
public void testOnlyOneNonHeaderINParameterRule() {
try {
assertNotNull(annotation);
assertEquals(SOAPBinding.class.getSimpleName(), AnnotationUtils.getAnnotationName(annotation));
IMethod method = source.findPrimaryType().getMethod("onlyOneIN", new String[] { "QString;",
"QString;" });
assertNotNull(method);
textFileChange.addEdit(AnnotationUtils.createAddImportTextEdit(method, SOAPBinding.class.getCanonicalName()));
textFileChange.addEdit(AnnotationUtils.createAddAnnotationTextEdit(method, annotation));
assertTrue(executeChange(new NullProgressMonitor(), textFileChange));
assertTrue(AnnotationUtils.isAnnotationPresent(method, 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.DOC_BARE_ONLY_ONE_NON_HEADER_IN_PARAMETER,
annotationProblemMarker.getAttribute(IMarker.MESSAGE));
} catch (CoreException ce) {
fail(ce.getLocalizedMessage());
} catch (OperationCanceledException oce) {
fail(oce.getLocalizedMessage());
} catch (InterruptedException ie) {
fail(ie.getLocalizedMessage());
}
}
public void testOnlyOneNonHeaderINParameterWithWebParamsRule() {
try {
assertNotNull(annotation);
assertEquals(SOAPBinding.class.getSimpleName(), AnnotationUtils.getAnnotationName(annotation));
IMethod method = source.findPrimaryType().getMethod("oneMore", new String[] { "QString;",
"QString;" });
assertNotNull(method);
textFileChange.addEdit(AnnotationUtils.createAddImportTextEdit(method, SOAPBinding.class.getCanonicalName()));
textFileChange.addEdit(AnnotationUtils.createAddAnnotationTextEdit(method, annotation));
assertTrue(executeChange(new NullProgressMonitor(), textFileChange));
assertTrue(AnnotationUtils.isAnnotationPresent(method, AnnotationUtils
.getAnnotationName(annotation)));
assertTrue(source.getImport(SOAPBinding.class.getCanonicalName()).exists());
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.DOC_BARE_ONLY_ONE_NON_HEADER_IN_PARAMETER,
annotationProblemMarker.getAttribute(IMarker.MESSAGE));
} catch (CoreException ce) {
fail(ce.getLocalizedMessage());
} catch (OperationCanceledException oce) {
fail(oce.getLocalizedMessage());
} catch (InterruptedException ie) {
fail(ie.getLocalizedMessage());
}
}
}