Skip to content

Commit

Permalink
adapt tests
Browse files Browse the repository at this point in the history
Signed-off-by: Iliyan Velichkov <velichkov.iliyan@gmail.com>
  • Loading branch information
iliyan-velichkov committed Dec 14, 2023
1 parent cac7590 commit 7d55fd1
Show file tree
Hide file tree
Showing 21 changed files with 4,064 additions and 3,886 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
/*******************************************************************************
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package org.apache.olingo.odata2.jpa.processor.core.mock;

Expand All @@ -24,24 +20,24 @@
import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;

public class ODataJPAServiceFactoryMock extends ODataJPAServiceFactory {
private ODataContext context = null;
private ODataContext context = null;

public ODataJPAServiceFactoryMock(final ODataContext context) {
this.context = context;
}
public ODataJPAServiceFactoryMock(final ODataContext context) {
this.context = context;
}

@Override
public ODataJPAContext initializeODataJPAContext() throws ODataJPARuntimeException {
ODataJPAContext oDataJPAContext = null;
oDataJPAContext = ODataJPAContextMock.mockODataJPAContext(context);
setOnWriteJPAContent(new OnJPAWriteContentMock());
return oDataJPAContext;
}
@Override
public ODataJPAContext initializeODataJPAContext() throws ODataJPARuntimeException {
ODataJPAContext oDataJPAContext = null;
oDataJPAContext = ODataJPAContextMock.mockODataJPAContext(context);
setOnWriteJPAContent(new OnJPAWriteContentMock());
return oDataJPAContext;
}

public ODataJPAContext initializeODataJPAContextX() throws ODataJPARuntimeException {
ODataJPAContext oDataJPAContext = null;
oDataJPAContext = ODataJPAContextMock.mockODataJPAContext(context);
setOnWriteJPAContent(null);
return oDataJPAContext;
}
public ODataJPAContext initializeODataJPAContextX() throws ODataJPARuntimeException {
ODataJPAContext oDataJPAContext = null;
oDataJPAContext = ODataJPAContextMock.mockODataJPAContext(context);
setOnWriteJPAContent(null);
return oDataJPAContext;
}
}
Original file line number Diff line number Diff line change
@@ -1,58 +1,47 @@
/*******************************************************************************
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package org.apache.olingo.odata2.jpa.processor.core.mock;

import java.sql.Blob;
import java.sql.Clob;
import java.sql.SQLException;

import jakarta.sql.rowset.serial.SerialBlob;
import jakarta.sql.rowset.serial.SerialClob;
import jakarta.sql.rowset.serial.SerialException;

import javax.sql.rowset.serial.SerialBlob;
import javax.sql.rowset.serial.SerialClob;
import org.apache.olingo.odata2.jpa.processor.api.OnJPAWriteContent;
import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;

public class OnJPAWriteContentMock implements OnJPAWriteContent {

@Override
public Blob getJPABlob(final byte[] binaryData) throws ODataJPARuntimeException {
try {
return new SerialBlob(binaryData);
} catch (SerialException e) {
ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
} catch (SQLException e) {
ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
@Override
public Blob getJPABlob(final byte[] binaryData) throws ODataJPARuntimeException {
try {
return new SerialBlob(binaryData);
} catch (SQLException e) {
ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
}
return null;
}
return null;
}

@Override
public Clob getJPAClob(final char[] characterData) throws ODataJPARuntimeException {
try {
return new SerialClob(characterData);
} catch (SerialException e) {
ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
} catch (SQLException e) {
ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
@Override
public Clob getJPAClob(final char[] characterData) throws ODataJPARuntimeException {
try {
return new SerialClob(characterData);
} catch (SQLException e) {
ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
}
return null;
}
return null;
}

}
Original file line number Diff line number Diff line change
@@ -1,70 +1,62 @@
/*******************************************************************************
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package org.apache.olingo.odata2.client.core.ep;

import static org.junit.Assert.assertEquals;

import java.util.Locale;

import org.apache.olingo.odata2.api.ep.EntityProviderException;
import org.apache.olingo.odata2.api.processor.ODataErrorContext;
import org.apache.olingo.odata2.client.api.ODataClient;
import org.apache.olingo.odata2.client.core.ep.deserializer.AbstractDeserializerTest;
import org.apache.olingo.odata2.testutil.helper.LocaleAsserter;
import org.apache.olingo.odata2.testutil.helper.StringHelper;
import org.junit.Test;

/**
*
*
*/
public class JSON_XMLErrorConsumerTest extends AbstractDeserializerTest {

private static final String JSON = "application/json";
private static final String XML = "application/xml";
@Test
public void readErrorDocumentJson() throws EntityProviderException {
ODataClient providerFacade = ODataClient.newInstance();
String errorDoc = "{\"error\":{\"code\":\"ErrorCode\",\"message\":{\"lang\":\"en-US\",\"value\":\"Message\"}}}";
ODataErrorContext errorContext = providerFacade.createDeserializer(JSON).
readErrorDocument(StringHelper.encapsulate(errorDoc));
//
assertEquals("Wrong content type", "application/json", errorContext.getContentType());
assertEquals("Wrong message", "Message", errorContext.getMessage());
assertEquals("Wrong error code", "ErrorCode", errorContext.getErrorCode());
assertEquals("Wrong locale for lang", Locale.US, errorContext.getLocale());
}
private static final String JSON = "application/json";
private static final String XML = "application/xml";

@Test
public void readErrorDocumentJson() throws EntityProviderException {
ODataClient providerFacade = ODataClient.newInstance();
String errorDoc = "{\"error\":{\"code\":\"ErrorCode\",\"message\":{\"lang\":\"en-US\",\"value\":\"Message\"}}}";
ODataErrorContext errorContext = providerFacade.createDeserializer(JSON)
.readErrorDocument(StringHelper.encapsulate(errorDoc));
//
assertEquals("Wrong content type", "application/json", errorContext.getContentType());
assertEquals("Wrong message", "Message", errorContext.getMessage());
assertEquals("Wrong error code", "ErrorCode", errorContext.getErrorCode());
LocaleAsserter.assertLocale("Wrong locale for lang", errorContext.getLocale(), Locale.US);
}

@Test
public void readErrorDocumentXml() throws EntityProviderException {
ODataClient providerFacade = ODataClient.newInstance();
String errorDoc =
"<?xml version='1.0' encoding='UTF-8'?>\n" +
"<error xmlns=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\">\n" +
"\t<code>ErrorCode</code>\n" +
"\t<message xml:lang=\"en-US\">Message</message>\n" +
"</error>";
ODataErrorContext errorContext = providerFacade.createDeserializer(XML).
readErrorDocument(StringHelper.encapsulate(errorDoc));
//
assertEquals("Wrong content type", "application/xml", errorContext.getContentType());
assertEquals("Wrong message", "Message", errorContext.getMessage());
assertEquals("Wrong error code", "ErrorCode", errorContext.getErrorCode());
assertEquals("Wrong locale for lang", Locale.US, errorContext.getLocale());
}
@Test
public void readErrorDocumentXml() throws EntityProviderException {
ODataClient providerFacade = ODataClient.newInstance();
String errorDoc = "<?xml version='1.0' encoding='UTF-8'?>\n"
+ "<error xmlns=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\">\n" + "\t<code>ErrorCode</code>\n"
+ "\t<message xml:lang=\"en-US\">Message</message>\n" + "</error>";
ODataErrorContext errorContext = providerFacade.createDeserializer(XML)
.readErrorDocument(StringHelper.encapsulate(errorDoc));
//
assertEquals("Wrong content type", "application/xml", errorContext.getContentType());
assertEquals("Wrong message", "Message", errorContext.getMessage());
assertEquals("Wrong error code", "ErrorCode", errorContext.getErrorCode());
LocaleAsserter.assertLocale("Wrong locale for lang", errorContext.getLocale(), Locale.US);
}
}
Loading

0 comments on commit 7d55fd1

Please sign in to comment.