Skip to content

Commit

Permalink
[OData] JavaDoc Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ThuF committed Dec 7, 2021
1 parent 4fe8dfb commit d470253
Show file tree
Hide file tree
Showing 11 changed files with 590 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ public interface IODataCoreService extends ICoreService {
/**
* Getter for the OData entity
*
* @param location
* @return
* @throws ODataException
* @param location the location
* @return ODataDefinition
* @throws ODataException in case of an error
*/
public ODataDefinition getOData(String location) throws ODataException;

Expand Down Expand Up @@ -382,7 +382,7 @@ public interface IODataCoreService extends ICoreService {
/**
* Removes the handlers
*
* @param location
* @param location the location
* @throws ODataException in case of an error
*/
public void removeHandlers(String location) throws ODataException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public DataSource createDataSource() {
}


protected String loadExpectedData(String fileName) throws IOException {
protected String loadResource(String fileName) throws IOException {
return IOUtils.toString(AbstractSQLPropcessorTest.class.getResourceAsStream(fileName), Charset.defaultCharset());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.apache.olingo.odata2.api.ODataServiceFactory;
import org.apache.olingo.odata2.api.commons.ODataHttpMethod;
import org.apache.olingo.odata2.api.exception.ODataException;
import org.apache.olingo.odata2.api.processor.ODataRequest.ODataRequestBuilder;
import org.apache.olingo.odata2.core.rest.ODataSubLocator;
import org.apache.olingo.odata2.core.rest.SubLocatorParameter;
import org.easymock.Capture;
Expand All @@ -56,10 +55,10 @@
/**
* Base class for OData API tests, which can be used to simulate calls to the OData API without having to use a servlet.
*
* In order to use the class, inherit from it and overwrite the {@link ODataRequestBuilder#getServiceFactoryClass()} method. You can use
* In order to use the class, inherit from it and overwrite the {@link OData2RequestBuilder#executeRequest(ODataHttpMethod)} method. You can use
* this method also to provide mock data to your API. If you API retrieves handles to data sources via the servlet context or the servlet
* request, use the {@link ODataRequestBuilder#enrichServletContextMock(ServletContext)} and
* {@link ODataRequestBuilder#enrichServletRequestMock(ServletRequest)} methods to provide the handles to you mock data.
* request, use the {@link OData2RequestBuilder#enrichServletContextMock(ServletContext)} and
* {@link OData2RequestBuilder#enrichServletRequestMock(ServletRequest)} methods to provide the handles to you mock data.
*
*/
public class OData2RequestBuilder {
Expand All @@ -76,35 +75,65 @@ public class OData2RequestBuilder {
private int contentSize = 1024 * 4;
private ODataServiceFactory serviceFactory;

/**
* @param pathSegmentStrings the path
* @return OData2RequestBuilder
*/
public OData2RequestBuilder segments(final String... pathSegmentStrings) {
pathSegmentStringList.addAll(Arrays.asList(pathSegmentStrings));
return this;
}

/**
* @param name the param name
* @param value the param value
* @return OData2RequestBuilder
*/
public OData2RequestBuilder param(final String name, final String value) {
queryParams.add(name, value);
return this;
}

/**
* @param accept the accept header
* @return OData2RequestBuilder
*/
public OData2RequestBuilder accept(final String accept) {
this.accept = accept;
return this;
}

/**
* @param contentSize the contentSize header
* @return OData2RequestBuilder
*/
public OData2RequestBuilder contentSize(final int contentSize) {
this.contentSize = contentSize;
return this;
}

/**
* @return executeRequest
* @throws IOException in case of error
* @throws ODataException in case of error
*/
public Response executeRequest() throws IOException, ODataException {
return executeRequest(GET);
}

/**
* @param serviceFactory serviceFactory
* @return OData2RequestBuilder
*/
public OData2RequestBuilder serviceFactory(ODataServiceFactory serviceFactory) {
this.serviceFactory = serviceFactory;
return this;
}

/**
* @param sf ODataServiceFactory
* @return OData2RequestBuilder
*/
public static OData2RequestBuilder createRequest(ODataServiceFactory sf) {
final OData2RequestBuilder request = new OData2RequestBuilder();
return request.serviceFactory(sf);
Expand All @@ -117,10 +146,8 @@ public static OData2RequestBuilder createRequest(ODataServiceFactory sf) {
* Mandatory parameter defining Http Method to be used for the request. Expected values are: GET, PUT, POST, DELETE, PATCH,
* MERGE
* @return OData Response
* @throws InstantiationException
* @throws IllegalAccessException
* @throws IOException
* @throws ODataException
* @throws IOException in case of error
* @throws ODataException in case of error
*/
public Response executeRequest(final ODataHttpMethod method) throws IOException, ODataException {

Expand Down Expand Up @@ -221,6 +248,12 @@ public List<String> answer() throws Throwable {
return response;
}

/**
* @param method the method
* @param easyMockSupport the easyMockSupport
* @param servletRequest the servletRequest
* @throws IOException in case of error
*/
protected void getServletInputStream(final ODataHttpMethod method, final EasyMockSupport easyMockSupport,
final HttpServletRequest servletRequest) throws IOException {
@SuppressWarnings("resource")
Expand All @@ -237,6 +270,10 @@ protected void getServletInputStream(final ODataHttpMethod method, final EasyMoc
expect(servletRequest.getInputStream()).andReturn(contentInputStream).atLeastOnce();
}

/**
* @param content the content
* @return OData2RequestBuilder
*/
public OData2RequestBuilder content(@SuppressWarnings("unused") final String content) { //NOSONAR to be overridden by subclasses
return this;
}
Expand All @@ -247,7 +284,7 @@ public OData2RequestBuilder content(@SuppressWarnings("unused") final String con
*
* @param servletContext
* the EasyMock instance of the {@link ServletContext}.
* @throws Exception
* @throws ODataException in case of error
*/
protected void enrichServletContextMock(final ServletContext servletContext) throws ODataException {
// default implementation is empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,49 @@

import static org.eclipse.dirigible.engine.odata2.sql.processor.DefaultSQLProcessor.DEFAULT_DATA_SOURCE_CONTEXT_KEY;

/**
* OData2TestServiceFactory
*
*/
public class OData2TestServiceFactory extends org.apache.olingo.odata2.api.ODataServiceFactory {

private final DataSource ds;
private final Class<?>[] edmAnnotatedClasses;
private final List<SQLInterceptor> interceptorList = new ArrayList<>();

/**
* @param ds the data source
* @param edmAnnotatedClasses the classes
* @throws ODataException in case of error
*/
public OData2TestServiceFactory(DataSource ds, Class<?>... edmAnnotatedClasses) throws ODataException {
this(ds, Collections.emptyList(), edmAnnotatedClasses);
}

/**
* @param ds the data source
* @param interceptorList the interceptor list
* @param edmAnnotatedClasses the classes
* @throws ODataException in case of error
*/
public OData2TestServiceFactory(DataSource ds, List<SQLInterceptor> interceptorList, Class<?>... edmAnnotatedClasses) throws ODataException {
this.ds = ds;
this.edmAnnotatedClasses = edmAnnotatedClasses;
addInterceptors(interceptorList);
}

/**
* @return AnnotationEdmProvider
* @throws ODataException in case of error
*/
public AnnotationEdmProvider createAnnotationEdmProvider() throws ODataException {
return new AnnotationEdmProvider(Collections.unmodifiableList(Arrays.asList(edmAnnotatedClasses)));

}

/**
* @param interceptorList the interceptor list
*/
public void addInterceptors(List<SQLInterceptor> interceptorList){
this.interceptorList.addAll(interceptorList);
}
Expand All @@ -67,6 +90,10 @@ public ODataService createService(ODataContext ctx) throws ODataException {
}
}

/**
* @param ctx the context
* @throws ODataException in case of error
*/
public void setDefaultDataSource(ODataContext ctx) throws ODataException {
ctx.setParameter(DEFAULT_DATA_SOURCE_CONTEXT_KEY, ds);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.olingo.odata2.api.ep.feed.ODataFeed;
import org.apache.olingo.odata2.api.exception.ODataException;
import org.apache.olingo.odata2.api.processor.ODataErrorContext;
import org.apache.olingo.odata2.api.processor.ODataRequest.ODataRequestBuilder;

import liquibase.Contexts;
import liquibase.LabelExpression;
Expand All @@ -43,21 +42,25 @@
import liquibase.exception.LiquibaseException;
import liquibase.resource.ClassLoaderResourceAccessor;

/**
* OData2TestUtils
*
*/
public class OData2TestUtils {

private OData2TestUtils() {
}

/**
* Helper method to retrieve the {@link ODataEntry} from the response object returned by {@link ODataRequestBuilder#executeRequest()}.
* Helper method to retrieve the {@link ODataEntry} from the response object returned by {@link OData2RequestBuilder#executeRequest()}.
*
* @param response
* the response returned by {@link ODataRequestBuilder#executeRequest()}
* the response returned by {@link OData2RequestBuilder#executeRequest()}
* @param entitySet
* the {@link EdmEntitySet} used to parse the response
* @return the {@link ODataEntry}
* @throws IOException
* @throws ODataException
* @throws IOException in case of error
* @throws ODataException in case of error
*/
public static ODataEntry retrieveODataEntryFromResponse(final Response response, final EdmEntitySet entitySet)
throws IOException, ODataException {
Expand All @@ -70,15 +73,15 @@ public static ODataEntry retrieveODataEntryFromResponse(final Response response,
}

/**
* Helper method to retrieve the {@link ODataFeed} from the response object returned by {@link ODataRequestBuilder#executeRequest()}.
* Helper method to retrieve the {@link ODataFeed} from the response object returned by {@link OData2RequestBuilder#executeRequest()}.
*
* @param response
* the response returned by {@link ODataRequestBuilder#executeRequest()}
* the response returned by {@link OData2RequestBuilder#executeRequest()}
* @param entitySet
* the {@link EdmEntitySet} used to parse the response
* @return the {@link ODataFeed}
* @throws IOException
* @throws ODataException
* @throws IOException in case of error
* @throws ODataException in case of error
*/
public static ODataFeed retrieveODataFeedFromResponse(final Response response, final EdmEntitySet entitySet)
throws IOException, ODataException {
Expand All @@ -92,14 +95,14 @@ public static ODataFeed retrieveODataFeedFromResponse(final Response response, f

/**
* Helper method to retrieve the {@link ODataErrorContext} representing the error response to a failed call to an OData API from the
* response object returned by {@link ODataRequestBuilder#executeRequest()}.
* response object returned by {@link OData2RequestBuilder#executeRequest()}.
*
* @param response
* the object containing the error response
* @return the ODataErrorContext representing the content of the returned error document. <b>NOTE:</b> The used parser does not parse
* the message's locale so it will always be <code>null</code>.
* @throws IOException
* @throws EntityProviderException
* @throws IOException in case of error
* @throws EntityProviderException in case of error
*/
public static ODataErrorContext retrieveODataErrorDocumentFromResponse(final Response response)
throws IOException, EntityProviderException {
Expand All @@ -108,10 +111,19 @@ public static ODataErrorContext retrieveODataErrorDocumentFromResponse(final Res
}
}

/**
* @param ns the namespace
* @param name the name
* @return FQN
*/
public static String fqn(String ns, String name) {
return ns + "." + name;
}

/**
* @param clazz the class
* @return FQN
*/
public static String fqn(Class<?> clazz) {
AnnotationHelper annotationHelper = new AnnotationHelper();
FullQualifiedName fqn = null;
Expand All @@ -128,6 +140,10 @@ public static String fqn(Class<?> clazz) {
return fqn.toString();
}

/**
* @param classes the classes
* @return list
*/
public static List<String> fqns(Class<?>... classes) {
List<String> fqns = new ArrayList<String>();
for (Class<?> clazz : classes) {
Expand All @@ -136,6 +152,10 @@ public static List<String> fqns(Class<?>... classes) {
return fqns;
}

/**
* @param classes the classes
* @return array
*/
@SuppressWarnings("rawtypes")
public static String[] resources(Class... classes) {
List<String> resources = new ArrayList<>();
Expand All @@ -145,14 +165,28 @@ public static String[] resources(Class... classes) {
return resources.toArray(new String[resources.size()]);
}

/**
* @param <T> T
* @param clazz class
* @return content
*/
public static <T> String resource(Class<T> clazz) {
return "META-INF/" + clazz.getSimpleName() + ".json";
}

/**
* @param <T> T
* @param clazz class
* @return InputStream
*/
public static <T> InputStream stream(Class<T> clazz) {
return OData2TestUtils.class.getClassLoader().getResourceAsStream(resource(clazz));
}

/**
* @param ds data source
* @throws SQLException in case of error
*/
public static void initLiquibase(DataSource ds) throws SQLException {
try (Connection connection = ds.getConnection()) {
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@

import org.apache.olingo.odata2.api.edm.EdmStructuralType;

/**
* SQLQueryTestUtils
*
*/
public class SQLQueryTestUtils {

private SQLQueryTestUtils() {
// Static class
}

/**
* @param sqlQuery
* @param structuralType
* @param sqlQuery the query
* @param structuralType the type
*/
public static void grantTableAliasForStructuralTypeInQuery(final SQLSelectBuilder sqlQuery, final EdmStructuralType structuralType) {
sqlQuery.grantTableAliasForStructuralTypeInQuery(structuralType);
Expand Down
Loading

0 comments on commit d470253

Please sign in to comment.