blob: cf4b7b539d89fc0f2d07a51561b99b5c9d0119ac [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2009 by SAP AG, Walldorf.
* 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:
* SAP AG - initial API and implementation
*******************************************************************************/
package org.eclipse.jst.ws.jaxws.dom.runtime.tests.dom.validation;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IType;
import org.eclipse.jst.ws.jaxws.dom.runtime.api.IServiceEndpointInterface;
import org.eclipse.jst.ws.jaxws.dom.runtime.validation.WsProblemsReporter;
import org.jmock.core.Constraint;
import org.jmock.core.constraint.IsGreaterThan;
public class WmValidationTest extends ValidationTestsSetUp
{
private IType seiType;
private IServiceEndpointInterface sei;
@Override
public void setUp() throws Exception
{
super.setUp();
seiType = testProject.createType(testPack, "Sei.java", "@javax.jws.WebService(name=\"SeiName\") public interface Sei {\n" +
"@javax.jws.WebMethod(operationName=\"test\") public void test();" +
"}");
}
public void testNameIsNCName() throws CoreException
{
IMarker [] markers = seiType.getResource().findMarkers(WsProblemsReporter.MARKER_ID, false, IResource.DEPTH_ZERO);
assertEquals(0, markers.length);
setContents(seiType.getCompilationUnit(), "@javax.jws.WebService(name=\"SeiName\") public interface Sei {\n" +
"@javax.jws.WebMethod(operationName=\"---\") public void test(); \n" + "}");
sei = findSei("test.Sei");
final Map<Object, Constraint> markerAttributes = new HashMap<Object, Constraint>();
markerAttributes.put(IMarker.CHAR_START, eq(109));
markerAttributes.put(IMarker.CHAR_END, eq(114));
markerAttributes.put(IMarker.LINE_NUMBER, eq(3));
markerAttributes.put(IMarker.SEVERITY, eq(IMarker.SEVERITY_ERROR));
final MarkerData markerData = new MarkerData(seiType.getResource(), WsProblemsReporter.MARKER_ID, markerAttributes);
validate(sei, markerData);
}
public void testNameIsUnique() throws CoreException
{
setContents(seiType.getCompilationUnit(), "@javax.jws.WebService(name=\"SeiName\") public interface Sei {\n" +
"@javax.jws.WebMethod(operationName=\"OpName\") public void first(); \n" +
"@javax.jws.WebMethod(operationName=\"OpName\") public void second(); \n" +
"}");
sei = findSei("test.Sei");
final Map<Object, Constraint> marker1_Attributes = new HashMap<Object, Constraint>();
marker1_Attributes.put(IMarker.CHAR_START, new IsGreaterThan(0));
marker1_Attributes.put(IMarker.CHAR_END, new IsGreaterThan(0));
marker1_Attributes.put(IMarker.SEVERITY, eq(IMarker.SEVERITY_ERROR));
final Map<Object, Constraint> marker2_Attributes = new HashMap<Object, Constraint>();
marker2_Attributes.put(IMarker.CHAR_START, new IsGreaterThan(0));
marker2_Attributes.put(IMarker.CHAR_END, new IsGreaterThan(0));
marker2_Attributes.put(IMarker.SEVERITY, eq(IMarker.SEVERITY_ERROR));
final MarkerData marker1_Data = new MarkerData(seiType.getResource(), WsProblemsReporter.MARKER_ID, marker1_Attributes);
final MarkerData marker2_Data = new MarkerData(seiType.getResource(), WsProblemsReporter.MARKER_ID, marker2_Attributes);
validate(sei, marker1_Data, marker2_Data);
}
public void testNameIsUniqueExcludedMethod() throws CoreException
{
setContents(seiType.getCompilationUnit(), "@javax.jws.WebService(name=\"SeiName\") public interface Sei {\n" +
"@javax.jws.WebMethod(exclude=true) public void first(); \n" +
"@javax.jws.WebMethod(operationName=\"first\") public void second(); \n" +
"}");
sei = findSei("test.Sei");
final Map<Object, Constraint> markerAttributes = new HashMap<Object, Constraint>();
markerAttributes.put(IMarker.CHAR_START, eq(103));
markerAttributes.put(IMarker.CHAR_END, eq(107));
markerAttributes.put(IMarker.SEVERITY, eq(IMarker.SEVERITY_ERROR));
final MarkerData markerData = new MarkerData(seiType.getResource(), WsProblemsReporter.MARKER_ID, markerAttributes);
validate(sei, markerData);
}
/**
* this test currently does nothing because excluded methods are not contained in
* the model.
*
* @throws CoreException
*/
public void testRedundantAttributesForExcludedMethod() throws CoreException
{
// setContents(seiType.getCompilationUnit(), "@javax.jws.WebService(name=\"SeiName\") public class Sei {\n" +
// "@javax.jws.WebMethod(exclude=true, operationName=\"OpName\") public void first(); \n" +
// "}");
//
// sei = findSei("test.Sei");
// IWebService ws = findWs("test.Sei");
//
// validator.validate(sei);
// IMarker [] markers = seiType.getResource().findMarkers(WsProblemsReporter.MARKER_ID, false, IResource.DEPTH_ZERO);
}
public void testMethodCannotBeExcludedInSEI() throws CoreException
{
setContents(seiType.getCompilationUnit(), "@javax.jws.WebService(name=\"SeiName\") public interface Sei {\n" +
"@javax.jws.WebMethod(exclude=true) public void first(); \n" +
"}");
sei = findSei("test.Sei");
final Map<Object, Constraint> markerAttributes = new HashMap<Object, Constraint>();
markerAttributes.put(IMarker.CHAR_START, eq(103));
markerAttributes.put(IMarker.CHAR_END, eq(107));
markerAttributes.put(IMarker.SEVERITY, eq(IMarker.SEVERITY_ERROR));
final MarkerData markerData = new MarkerData(seiType.getResource(), WsProblemsReporter.MARKER_ID, markerAttributes);
validate(sei, markerData);
}
}