src_fm_fc_ms_ff
stringlengths 43
86.8k
| target
stringlengths 20
276k
|
---|---|
Key { protected java.security.Key getSigningKeySpec() { return new SecretKeySpec(getSigningKey(), getSigningAlgorithm()); } Key(final byte[] signingKey, final byte[] encryptionKey); Key(final byte[] concatenatedKeys); Key(final String string); static Key generateKey(); static Key generateKey(final SecureRandom random); byte[] sign(final byte version, final Instant timestamp, final IvParameterSpec initializationVector,
final byte[] cipherText); @SuppressWarnings("PMD.LawOfDemeter") byte[] encrypt(final byte[] payload, final IvParameterSpec initializationVector); @SuppressWarnings("PMD.LawOfDemeter") String serialise(); void writeTo(final OutputStream outputStream); int hashCode(); @SuppressWarnings("PMD.LawOfDemeter") boolean equals(final Object obj); } | @Test public void testGetSigningKeySpec() { final Key key = new Key("AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyA="); final java.security.Key result = key.getSigningKeySpec(); assertEquals("HmacSHA256", result.getAlgorithm()); } |
Key { protected SecretKeySpec getEncryptionKeySpec() { return new SecretKeySpec(getEncryptionKey(), getEncryptionAlgorithm()); } Key(final byte[] signingKey, final byte[] encryptionKey); Key(final byte[] concatenatedKeys); Key(final String string); static Key generateKey(); static Key generateKey(final SecureRandom random); byte[] sign(final byte version, final Instant timestamp, final IvParameterSpec initializationVector,
final byte[] cipherText); @SuppressWarnings("PMD.LawOfDemeter") byte[] encrypt(final byte[] payload, final IvParameterSpec initializationVector); @SuppressWarnings("PMD.LawOfDemeter") String serialise(); void writeTo(final OutputStream outputStream); int hashCode(); @SuppressWarnings("PMD.LawOfDemeter") boolean equals(final Object obj); } | @Test public void testGetEncryptionKeySpec() { final Key key = new Key("AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyA="); final SecretKeySpec result = key.getEncryptionKeySpec(); assertEquals("AES", result.getAlgorithm()); } |
Key { @SuppressWarnings("PMD.LawOfDemeter") public String serialise() { try (ByteArrayOutputStream byteStream = new ByteArrayOutputStream(fernetKeyBytes)) { writeTo(byteStream); return getEncoder().encodeToString(byteStream.toByteArray()); } catch (final IOException ioe) { throw new IllegalStateException(ioe.getMessage(), ioe); } } Key(final byte[] signingKey, final byte[] encryptionKey); Key(final byte[] concatenatedKeys); Key(final String string); static Key generateKey(); static Key generateKey(final SecureRandom random); byte[] sign(final byte version, final Instant timestamp, final IvParameterSpec initializationVector,
final byte[] cipherText); @SuppressWarnings("PMD.LawOfDemeter") byte[] encrypt(final byte[] payload, final IvParameterSpec initializationVector); @SuppressWarnings("PMD.LawOfDemeter") String serialise(); void writeTo(final OutputStream outputStream); int hashCode(); @SuppressWarnings("PMD.LawOfDemeter") boolean equals(final Object obj); } | @Test public void testSerialise() { final Key key = new Key(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, new byte[] {17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}); final String result = key.serialise(); assertEquals("AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyA=", result); } |
TokenHeaderUtility { public Token getXAuthorizationToken(final ContainerRequest request) { final String xAuthorizationString = request.getHeaderString("X-Authorization"); if (xAuthorizationString != null && !"".equals(xAuthorizationString)) { return Token.fromString(xAuthorizationString.trim()); } return null; } @SuppressWarnings("PMD.AvoidLiteralsInIfCondition") Token getAuthorizationToken(final ContainerRequest request); Token getXAuthorizationToken(final ContainerRequest request); } | @Test public final void verifyGetXAuthorizationTokenDeserialisesToken() { final Key key = Key.generateKey(random); final Token token = Token.generate(random, key, "hello"); final ContainerRequest request = mock(ContainerRequest.class); given(request.getHeaderString("X-Authorization")).willReturn(token.serialise()); final Token result = utility.getXAuthorizationToken(request); assertEquals(token.serialise(), result.serialise()); }
@Test public final void verifyGetXAuthorizationTokenIgnoresBearer() { final Key key = Key.generateKey(random); final Token token = Token.generate(random, key, "hello"); final ContainerRequest request = mock(ContainerRequest.class); given(request.getHeaderString("Authorization")).willReturn("Bearer " + token.serialise()); final Token result = utility.getXAuthorizationToken(request); assertNull(result); } |
TokenValidationExceptionMapper implements ExceptionMapper<TokenValidationException> { public Response toResponse(final TokenValidationException exception) { if (exception instanceof PayloadValidationException) { return status(FORBIDDEN).entity("Request could not be validated.").type(TEXT_PLAIN_TYPE).build(); } return new NotAuthorizedException("Bearer error=\"invalid_token\"").getResponse(); } Response toResponse(final TokenValidationException exception); } | @Test public final void verifyToResponseGeneratesForbidden() { final PayloadValidationException exception = new PayloadValidationException("Invalid payload"); final Response response = mapper.toResponse(exception); assertEquals(403, response.getStatus()); }
@Test public final void verifyToResponseGeneratesUnauthorized() { final TokenValidationException exception = new TokenExpiredException("token expired"); final Response response = mapper.toResponse(exception); assertEquals(401, response.getStatus()); final String challenge = response.getHeaderString("WWW-Authenticate"); assertTrue(challenge.startsWith("Bearer ")); } |
MemoryOverwritingRequestHandler extends RequestHandler2 { public void afterResponse(final Request<?> request, final Response<?> response) { final Object requestObject = request.getOriginalRequestObject(); if (requestObject instanceof PutSecretValueRequest) { final PutSecretValueRequest putRequest = (PutSecretValueRequest) requestObject; overwriteSecret(putRequest); } } MemoryOverwritingRequestHandler(final SecureRandom random); void afterResponse(final Request<?> request, final Response<?> response); void afterError(final Request<?> request, final Response<?> response, final Exception exception); } | @Test public void verifyAfterResponseClearsSecret() { final ByteBuffer secretBinary = ByteBuffer.wrap(new byte[] { 1, 1, 2, 3, 5, 8 }); assertTrue(Arrays.equals(secretBinary.array(), new byte[] { 1, 1, 2, 3, 5, 8})); final PutSecretValueRequest originalRequest = new PutSecretValueRequest(); originalRequest.setSecretBinary(secretBinary); final Request<PutSecretValueRequest> request = new DefaultRequest<PutSecretValueRequest>(originalRequest, "AWSSecretsManager"); final PutSecretValueResult result = mock(PutSecretValueResult.class); final HttpResponse httpResponse = mock(HttpResponse.class); final Response<PutSecretValueResult> response = new Response<PutSecretValueResult>(result, httpResponse); handler.afterResponse(request, response); assertFalse(Arrays.equals(secretBinary.array(), new byte[] { 1, 1, 2, 3, 5, 8})); } |
MemoryOverwritingRequestHandler extends RequestHandler2 { public void afterError(final Request<?> request, final Response<?> response, final Exception exception) { final Object requestObject = request.getOriginalRequestObject(); if (requestObject instanceof PutSecretValueRequest) { final PutSecretValueRequest putRequest = (PutSecretValueRequest) requestObject; overwriteSecret(putRequest); } } MemoryOverwritingRequestHandler(final SecureRandom random); void afterResponse(final Request<?> request, final Response<?> response); void afterError(final Request<?> request, final Response<?> response, final Exception exception); } | @Test public void verifyAfterErrorClearsSecret() { final ByteBuffer secretBinary = ByteBuffer.wrap(new byte[] { 1, 1, 2, 3, 5, 8 }); assertTrue(Arrays.equals(secretBinary.array(), new byte[] { 1, 1, 2, 3, 5, 8})); final PutSecretValueRequest originalRequest = new PutSecretValueRequest(); originalRequest.setSecretBinary(secretBinary); final Request<PutSecretValueRequest> request = new DefaultRequest<PutSecretValueRequest>(originalRequest, "AWSSecretsManager"); final PutSecretValueResult result = mock(PutSecretValueResult.class); final HttpResponse httpResponse = mock(HttpResponse.class); final Response<PutSecretValueResult> response = new Response<PutSecretValueResult>(result, httpResponse); handler.afterError(request, response, new Exception()); assertFalse(Arrays.equals(secretBinary.array(), new byte[] { 1, 1, 2, 3, 5, 8})); } |
Team { public String getId() { return Integer.toString(id); } Team(final int id, final String name); String getId(); String getName(); void setName(final String name); boolean isScrumTeam(); void setScrumTeam(final boolean isScrumTeam); List<Employee> getEmployees(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString(); } | @Test public void testId() { Team team1 = new Team(1, null); assertNotNull(team1.getId()); } |
JPAEdmModel extends JPAEdmBaseViewImpl implements JPAEdmModelView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmModelBuilder(); } return builder; } JPAEdmModel(final Metamodel metaModel, final String pUnitName); JPAEdmModel(final ODataJPAContext ctx); @Override JPAEdmSchemaView getEdmSchemaView(); @Override JPAEdmBuilder getBuilder(); } | @Test public void testGetBuilder() { assertNotNull(objJPAEdmModel.getBuilder()); } |
JPAEdmAssociationSet extends JPAEdmBaseViewImpl implements
JPAEdmAssociationSetView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmAssociationSetBuilder(); } return builder; } JPAEdmAssociationSet(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<AssociationSet> getConsistentEdmAssociationSetList(); @Override AssociationSet getEdmAssociationSet(); @Override Association getEdmAssociation(); } | @Test public void testGetBuilder() { assertNotNull(objJPAEdmAssociationSet.getBuilder()); }
@Test public void testGetBuilderIdempotent() { JPAEdmBuilder builder1 = objJPAEdmAssociationSet.getBuilder(); JPAEdmBuilder builder2 = objJPAEdmAssociationSet.getBuilder(); assertEquals(builder1.hashCode(), builder2.hashCode()); } |
JPAEdmAssociationSet extends JPAEdmBaseViewImpl implements
JPAEdmAssociationSetView { @Override public List<AssociationSet> getConsistentEdmAssociationSetList() { return associationSetList; } JPAEdmAssociationSet(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<AssociationSet> getConsistentEdmAssociationSetList(); @Override AssociationSet getEdmAssociationSet(); @Override Association getEdmAssociation(); } | @Test public void testGetConsistentEdmAssociationSetList() { assertNotNull(objJPAEdmAssociationSet.getConsistentEdmAssociationSetList()); } |
JPAEdmAssociationSet extends JPAEdmBaseViewImpl implements
JPAEdmAssociationSetView { @Override public AssociationSet getEdmAssociationSet() { return currentAssociationSet; } JPAEdmAssociationSet(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<AssociationSet> getConsistentEdmAssociationSetList(); @Override AssociationSet getEdmAssociationSet(); @Override Association getEdmAssociation(); } | @Test public void testGetEdmAssociationSet() { assertNotNull(objJPAEdmAssociationSet.getEdmAssociationSet()); } |
JPAEdmAssociationSet extends JPAEdmBaseViewImpl implements
JPAEdmAssociationSetView { @Override public Association getEdmAssociation() { return currentAssociation; } JPAEdmAssociationSet(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<AssociationSet> getConsistentEdmAssociationSetList(); @Override AssociationSet getEdmAssociationSet(); @Override Association getEdmAssociation(); } | @Test public void testGetEdmAssociation() { assertNotNull(objJPAEdmAssociationSet.getEdmAssociation()); } |
JPAEdmBaseViewImpl implements JPAEdmBaseView { @Override public String getpUnitName() { return pUnitName; } JPAEdmBaseViewImpl(final JPAEdmBaseView view); JPAEdmBaseViewImpl(final ODataJPAContext context); JPAEdmBaseViewImpl(final Metamodel metaModel, final String pUnitName); @Override String getpUnitName(); @Override Metamodel getJPAMetaModel(); @Override boolean isConsistent(); @Override void clean(); @Override JPAEdmMappingModelAccess getJPAEdmMappingModelAccess(); @Override JPAEdmExtension getJPAEdmExtension(); } | @Test public void testGetpUnitName() { assertTrue(objJPAEdmBaseViewImpl.getpUnitName().equals("salesorderprocessing")); } |
JPAEdmBaseViewImpl implements JPAEdmBaseView { @Override public Metamodel getJPAMetaModel() { return metaModel; } JPAEdmBaseViewImpl(final JPAEdmBaseView view); JPAEdmBaseViewImpl(final ODataJPAContext context); JPAEdmBaseViewImpl(final Metamodel metaModel, final String pUnitName); @Override String getpUnitName(); @Override Metamodel getJPAMetaModel(); @Override boolean isConsistent(); @Override void clean(); @Override JPAEdmMappingModelAccess getJPAEdmMappingModelAccess(); @Override JPAEdmExtension getJPAEdmExtension(); } | @Test public void testGetJPAMetaModel() { assertNotNull(objJPAEdmBaseViewImpl.getJPAMetaModel()); } |
JPAEdmBaseViewImpl implements JPAEdmBaseView { @Override public boolean isConsistent() { return isConsistent; } JPAEdmBaseViewImpl(final JPAEdmBaseView view); JPAEdmBaseViewImpl(final ODataJPAContext context); JPAEdmBaseViewImpl(final Metamodel metaModel, final String pUnitName); @Override String getpUnitName(); @Override Metamodel getJPAMetaModel(); @Override boolean isConsistent(); @Override void clean(); @Override JPAEdmMappingModelAccess getJPAEdmMappingModelAccess(); @Override JPAEdmExtension getJPAEdmExtension(); } | @Test public void testIsConsistent() { assertTrue(objJPAEdmBaseViewImpl.isConsistent()); } |
JPAEdmBaseViewImpl implements JPAEdmBaseView { @Override public void clean() { pUnitName = null; metaModel = null; isConsistent = false; } JPAEdmBaseViewImpl(final JPAEdmBaseView view); JPAEdmBaseViewImpl(final ODataJPAContext context); JPAEdmBaseViewImpl(final Metamodel metaModel, final String pUnitName); @Override String getpUnitName(); @Override Metamodel getJPAMetaModel(); @Override boolean isConsistent(); @Override void clean(); @Override JPAEdmMappingModelAccess getJPAEdmMappingModelAccess(); @Override JPAEdmExtension getJPAEdmExtension(); } | @Test public void testClean() { objJPAEdmBaseViewImpl.clean(); assertFalse(objJPAEdmBaseViewImpl.isConsistent()); } |
Building { public List<Room> getRooms() { return rooms; } Building(final int id, final String name); String getId(); void setName(final String name); String getName(); void setImage(final byte[] byteArray); byte[] getImage(); List<Room> getRooms(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString(); } | @Test public void testRooms() { List<Room> list = Arrays.asList(new Room(1, null), new Room(2, null), new Room(3, null)); Building building1 = new Building(1, null); building1.getRooms().add(list.get(0)); building1.getRooms().add(list.get(1)); building1.getRooms().add(list.get(2)); assertEquals(list, building1.getRooms()); } |
JPAEdmComplexType extends JPAEdmBaseViewImpl implements
JPAEdmComplexTypeView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmComplexTypeBuilder(); } return builder; } JPAEdmComplexType(final JPAEdmSchemaView view); JPAEdmComplexType(final JPAEdmSchemaView view, final Attribute<?, ?> complexAttribute); @Override JPAEdmBuilder getBuilder(); @Override ComplexType getEdmComplexType(); @Override ComplexType searchEdmComplexType(final String embeddableTypeName); @Override EmbeddableType<?> getJPAEmbeddableType(); @Override List<ComplexType> getConsistentEdmComplexTypes(); @Override ComplexType searchEdmComplexType(final FullQualifiedName type); @Override void addJPAEdmCompleTypeView(final JPAEdmComplexTypeView view); @Override void expandEdmComplexType(final ComplexType complexType, List<Property> expandedList, final String embeddablePropertyName); } | @Test public void testGetBuilder() { assertNotNull(objComplexType.getBuilder()); }
@Test public void testGetBuilderIdempotent() { JPAEdmBuilder builder1 = objComplexType.getBuilder(); JPAEdmBuilder builder2 = objComplexType.getBuilder(); assertEquals(builder1.hashCode(), builder2.hashCode()); }
@Test public void testComplexTypeCreation() { try { objComplexType.getBuilder().build(); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } assertEquals(objComplexType.pUnitName, "salesorderprocessing"); } |
JPAEdmComplexType extends JPAEdmBaseViewImpl implements
JPAEdmComplexTypeView { @Override public ComplexType getEdmComplexType() { return currentComplexType; } JPAEdmComplexType(final JPAEdmSchemaView view); JPAEdmComplexType(final JPAEdmSchemaView view, final Attribute<?, ?> complexAttribute); @Override JPAEdmBuilder getBuilder(); @Override ComplexType getEdmComplexType(); @Override ComplexType searchEdmComplexType(final String embeddableTypeName); @Override EmbeddableType<?> getJPAEmbeddableType(); @Override List<ComplexType> getConsistentEdmComplexTypes(); @Override ComplexType searchEdmComplexType(final FullQualifiedName type); @Override void addJPAEdmCompleTypeView(final JPAEdmComplexTypeView view); @Override void expandEdmComplexType(final ComplexType complexType, List<Property> expandedList, final String embeddablePropertyName); } | @Test public void testGetEdmComplexType() { assertEquals(objComplexType.getEdmComplexType().getName(), "String"); } |
JPAEdmComplexType extends JPAEdmBaseViewImpl implements
JPAEdmComplexTypeView { @Override public ComplexType searchEdmComplexType(final String embeddableTypeName) { return searchMap.get(embeddableTypeName); } JPAEdmComplexType(final JPAEdmSchemaView view); JPAEdmComplexType(final JPAEdmSchemaView view, final Attribute<?, ?> complexAttribute); @Override JPAEdmBuilder getBuilder(); @Override ComplexType getEdmComplexType(); @Override ComplexType searchEdmComplexType(final String embeddableTypeName); @Override EmbeddableType<?> getJPAEmbeddableType(); @Override List<ComplexType> getConsistentEdmComplexTypes(); @Override ComplexType searchEdmComplexType(final FullQualifiedName type); @Override void addJPAEdmCompleTypeView(final JPAEdmComplexTypeView view); @Override void expandEdmComplexType(final ComplexType complexType, List<Property> expandedList, final String embeddablePropertyName); } | @Test public void testSearchComplexTypeString() { assertNotNull(objComplexType.searchEdmComplexType("java.lang.String")); }
@Test public void testSearchComplexTypeFullQualifiedName() { assertNotNull(objComplexType.searchEdmComplexType(new FullQualifiedName("salesorderprocessing", "String"))); }
@Test public void testSearchComplexTypeFullQualifiedNameNegative() { assertNull(objComplexType.searchEdmComplexType(new FullQualifiedName("salesorderprocessing", "lang.String"))); } |
JPAEdmComplexType extends JPAEdmBaseViewImpl implements
JPAEdmComplexTypeView { @Override public EmbeddableType<?> getJPAEmbeddableType() { return currentEmbeddableType; } JPAEdmComplexType(final JPAEdmSchemaView view); JPAEdmComplexType(final JPAEdmSchemaView view, final Attribute<?, ?> complexAttribute); @Override JPAEdmBuilder getBuilder(); @Override ComplexType getEdmComplexType(); @Override ComplexType searchEdmComplexType(final String embeddableTypeName); @Override EmbeddableType<?> getJPAEmbeddableType(); @Override List<ComplexType> getConsistentEdmComplexTypes(); @Override ComplexType searchEdmComplexType(final FullQualifiedName type); @Override void addJPAEdmCompleTypeView(final JPAEdmComplexTypeView view); @Override void expandEdmComplexType(final ComplexType complexType, List<Property> expandedList, final String embeddablePropertyName); } | @Test public void testGetJPAEmbeddableType() { assertTrue(objComplexType.getJPAEmbeddableType().getAttributes().size() > 0); } |
JPAEdmComplexType extends JPAEdmBaseViewImpl implements
JPAEdmComplexTypeView { @Override public List<ComplexType> getConsistentEdmComplexTypes() { return consistentComplextTypes; } JPAEdmComplexType(final JPAEdmSchemaView view); JPAEdmComplexType(final JPAEdmSchemaView view, final Attribute<?, ?> complexAttribute); @Override JPAEdmBuilder getBuilder(); @Override ComplexType getEdmComplexType(); @Override ComplexType searchEdmComplexType(final String embeddableTypeName); @Override EmbeddableType<?> getJPAEmbeddableType(); @Override List<ComplexType> getConsistentEdmComplexTypes(); @Override ComplexType searchEdmComplexType(final FullQualifiedName type); @Override void addJPAEdmCompleTypeView(final JPAEdmComplexTypeView view); @Override void expandEdmComplexType(final ComplexType complexType, List<Property> expandedList, final String embeddablePropertyName); } | @Test public void testGetConsistentEdmComplexTypes() { assertTrue(objComplexType.getConsistentEdmComplexTypes().size() > 0); } |
JPAEdmComplexType extends JPAEdmBaseViewImpl implements
JPAEdmComplexTypeView { @Override public void expandEdmComplexType(final ComplexType complexType, List<Property> expandedList, final String embeddablePropertyName) { if (expandedList == null) { expandedList = new ArrayList<Property>(); } for (Property property : complexType.getProperties()) { try { SimpleProperty newSimpleProperty = new SimpleProperty(); SimpleProperty oldSimpleProperty = (SimpleProperty) property; newSimpleProperty.setAnnotationAttributes(oldSimpleProperty.getAnnotationAttributes()); newSimpleProperty.setAnnotationElements(oldSimpleProperty.getAnnotationElements()); newSimpleProperty.setCustomizableFeedMappings(oldSimpleProperty.getCustomizableFeedMappings()); newSimpleProperty.setDocumentation(oldSimpleProperty.getDocumentation()); newSimpleProperty.setFacets(oldSimpleProperty.getFacets()); newSimpleProperty.setMimeType(oldSimpleProperty.getMimeType()); newSimpleProperty.setName(oldSimpleProperty.getName()); newSimpleProperty.setType(oldSimpleProperty.getType()); JPAEdmMappingImpl newMapping = new JPAEdmMappingImpl(); Mapping mapping = oldSimpleProperty.getMapping(); JPAEdmMapping oldMapping = (JPAEdmMapping) mapping; newMapping.setJPAColumnName(oldMapping.getJPAColumnName()); newMapping.setInternalName(embeddablePropertyName + "." + mapping.getInternalName()); newMapping.setMimeType(mapping.getMimeType()); newMapping.setObject(mapping.getObject()); newMapping.setJPAType(oldMapping.getJPAType()); newSimpleProperty.setMapping(newMapping); expandedList.add(newSimpleProperty); } catch (ClassCastException e) { ComplexProperty complexProperty = (ComplexProperty) property; String name = embeddablePropertyName + "." + complexProperty.getMapping().getInternalName(); expandEdmComplexType(searchComplexTypeByName(complexProperty.getName()), expandedList, name); } } } JPAEdmComplexType(final JPAEdmSchemaView view); JPAEdmComplexType(final JPAEdmSchemaView view, final Attribute<?, ?> complexAttribute); @Override JPAEdmBuilder getBuilder(); @Override ComplexType getEdmComplexType(); @Override ComplexType searchEdmComplexType(final String embeddableTypeName); @Override EmbeddableType<?> getJPAEmbeddableType(); @Override List<ComplexType> getConsistentEdmComplexTypes(); @Override ComplexType searchEdmComplexType(final FullQualifiedName type); @Override void addJPAEdmCompleTypeView(final JPAEdmComplexTypeView view); @Override void expandEdmComplexType(final ComplexType complexType, List<Property> expandedList, final String embeddablePropertyName); } | @Test public void testExpandEdmComplexType() { ComplexType complexType = new ComplexType(); List<Property> properties = new ArrayList<Property>(); JPAEdmMapping mapping1 = new JPAEdmMappingImpl(); mapping1.setJPAColumnName("LINEITEMID"); ((Mapping) mapping1).setInternalName("LineItemKey.LiId"); JPAEdmMapping mapping2 = new JPAEdmMappingImpl(); mapping2.setJPAColumnName("LINEITEMNAME"); ((Mapping) mapping2).setInternalName("LineItemKey.LiName"); properties.add(new SimpleProperty().setName("LIID").setMapping((Mapping) mapping1)); properties.add(new SimpleProperty().setName("LINAME").setMapping((Mapping) mapping2)); complexType.setProperties(properties); List<Property> expandedList = null; try { objComplexType.expandEdmComplexType(complexType, expandedList, "SalesOrderItemKey"); } catch (ClassCastException e) { assertTrue(false); } assertTrue(true); } |
Employee { public String getId() { return Integer.toString(employeeId); } Employee(final int employeeId, final String name); String getId(); void setEmployeeName(final String employeeName); String getEmployeeName(); void setAge(final int age); int getAge(); void setManager(final Manager manager); Manager getManager(); void setTeam(final Team team); Team getTeam(); void setRoom(final Room room); Room getRoom(); void setImageUri(final String imageUri); String getImageUri(); void setLocation(final Location location); Location getLocation(); void setEntryDate(final Calendar date); Calendar getEntryDate(); void setImageType(final String imageType); String getImageType(); void setImage(final byte[] image); void setImage(final String imageUrl); byte[] getImage(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString(); } | @Test public void testId() { Employee employee1 = new Employee(1, null); assertNotNull(employee1.getId()); } |
JPAEdmReferentialConstraint extends JPAEdmBaseViewImpl implements
JPAEdmReferentialConstraintView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmRefConstraintBuilder(); } return builder; } JPAEdmReferentialConstraint(final JPAEdmAssociationView associationView,
final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView); @Override JPAEdmBuilder getBuilder(); @Override ReferentialConstraint getEdmReferentialConstraint(); @Override boolean isExists(); @Override String getEdmRelationShipName(); } | @Test public void testGetBuilder() { assertNotNull(objJPAEdmReferentialConstraint.getBuilder()); }
@Test public void testGetBuilderIdempotent() { JPAEdmBuilder builder1 = objJPAEdmReferentialConstraint.getBuilder(); JPAEdmBuilder builder2 = objJPAEdmReferentialConstraint.getBuilder(); assertEquals(builder1.hashCode(), builder2.hashCode()); } |
JPAEdmReferentialConstraint extends JPAEdmBaseViewImpl implements
JPAEdmReferentialConstraintView { @Override public ReferentialConstraint getEdmReferentialConstraint() { return referentialConstraint; } JPAEdmReferentialConstraint(final JPAEdmAssociationView associationView,
final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView); @Override JPAEdmBuilder getBuilder(); @Override ReferentialConstraint getEdmReferentialConstraint(); @Override boolean isExists(); @Override String getEdmRelationShipName(); } | @Test public void testGetEdmReferentialConstraint() { assertNotNull(objJPAEdmReferentialConstraint .getEdmReferentialConstraint()); } |
JPAEdmReferentialConstraint extends JPAEdmBaseViewImpl implements
JPAEdmReferentialConstraintView { @Override public String getEdmRelationShipName() { return relationShipName; } JPAEdmReferentialConstraint(final JPAEdmAssociationView associationView,
final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView); @Override JPAEdmBuilder getBuilder(); @Override ReferentialConstraint getEdmReferentialConstraint(); @Override boolean isExists(); @Override String getEdmRelationShipName(); } | @Test public void testGetRelationShipName() { assertEquals("Assoc_SalesOrderHeader_SalesOrderItem", objJPAEdmReferentialConstraint.getEdmRelationShipName()); } |
JPAEdmAssociationEnd extends JPAEdmBaseViewImpl implements
JPAEdmAssociationEndView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmAssociationEndBuilder(); } return builder; } JPAEdmAssociationEnd(final JPAEdmEntityTypeView entityTypeView,
final JPAEdmPropertyView propertyView); @Override JPAEdmBuilder getBuilder(); @Override AssociationEnd getEdmAssociationEnd1(); @Override AssociationEnd getEdmAssociationEnd2(); @Override boolean compare(final AssociationEnd end1, final AssociationEnd end2); @Override String getJoinColumnName(); @Override String getJoinColumnReferenceColumnName(); @Override String getMappedByName(); @Override String getOwningPropertyName(); } | @Test public void testGetBuilder() { JPAEdmBuilder builder = objJPAEdmAssociationEnd.getBuilder(); assertNotNull(builder); }
@Test public void testGetBuilderIdempotent() { JPAEdmBuilder builder1 = objJPAEdmAssociationEnd.getBuilder(); JPAEdmBuilder builder2 = objJPAEdmAssociationEnd.getBuilder(); assertEquals(builder1.hashCode(), builder2.hashCode()); } |
JPAEdmAssociationEnd extends JPAEdmBaseViewImpl implements
JPAEdmAssociationEndView { @Override public AssociationEnd getEdmAssociationEnd1() { return currentAssociationEnd1; } JPAEdmAssociationEnd(final JPAEdmEntityTypeView entityTypeView,
final JPAEdmPropertyView propertyView); @Override JPAEdmBuilder getBuilder(); @Override AssociationEnd getEdmAssociationEnd1(); @Override AssociationEnd getEdmAssociationEnd2(); @Override boolean compare(final AssociationEnd end1, final AssociationEnd end2); @Override String getJoinColumnName(); @Override String getJoinColumnReferenceColumnName(); @Override String getMappedByName(); @Override String getOwningPropertyName(); } | @Test public void testGetAssociationEnd1() { AssociationEnd associationEnd = objJPAEdmAssociationEnd .getEdmAssociationEnd1(); assertEquals(associationEnd.getType().getName(), "SOID"); }
@Test public void testBuildAssociationEnd() { assertEquals("SOID", objJPAEdmAssociationEnd.getEdmAssociationEnd1().getType().getName()); assertEquals(new FullQualifiedName("salesorderprocessing", "SOID"), objJPAEdmAssociationEnd.getEdmAssociationEnd1().getType()); assertTrue(objJPAEdmAssociationEnd.isConsistent()); } |
JPAEdmAssociationEnd extends JPAEdmBaseViewImpl implements
JPAEdmAssociationEndView { @Override public AssociationEnd getEdmAssociationEnd2() { return currentAssociationEnd2; } JPAEdmAssociationEnd(final JPAEdmEntityTypeView entityTypeView,
final JPAEdmPropertyView propertyView); @Override JPAEdmBuilder getBuilder(); @Override AssociationEnd getEdmAssociationEnd1(); @Override AssociationEnd getEdmAssociationEnd2(); @Override boolean compare(final AssociationEnd end1, final AssociationEnd end2); @Override String getJoinColumnName(); @Override String getJoinColumnReferenceColumnName(); @Override String getMappedByName(); @Override String getOwningPropertyName(); } | @Test public void testGetAssociationEnd2() { AssociationEnd associationEnd = objJPAEdmAssociationEnd .getEdmAssociationEnd2(); assertEquals(associationEnd.getType().getName(), "String"); } |
JPAEdmAssociationEnd extends JPAEdmBaseViewImpl implements
JPAEdmAssociationEndView { @Override public boolean compare(final AssociationEnd end1, final AssociationEnd end2) { if ((end1.getType().equals(currentAssociationEnd1.getType()) && end2.getType().equals(currentAssociationEnd2.getType()) && end1.getMultiplicity().equals( currentAssociationEnd1.getMultiplicity()) && end2 .getMultiplicity().equals( currentAssociationEnd2.getMultiplicity())) || (end1.getType().equals(currentAssociationEnd2.getType()) && end2.getType().equals( currentAssociationEnd1.getType()) && end1.getMultiplicity().equals( currentAssociationEnd2.getMultiplicity()) && end2 .getMultiplicity().equals( currentAssociationEnd1.getMultiplicity()))) { return true; } return false; } JPAEdmAssociationEnd(final JPAEdmEntityTypeView entityTypeView,
final JPAEdmPropertyView propertyView); @Override JPAEdmBuilder getBuilder(); @Override AssociationEnd getEdmAssociationEnd1(); @Override AssociationEnd getEdmAssociationEnd2(); @Override boolean compare(final AssociationEnd end1, final AssociationEnd end2); @Override String getJoinColumnName(); @Override String getJoinColumnReferenceColumnName(); @Override String getMappedByName(); @Override String getOwningPropertyName(); } | @Test public void testCompare() { assertTrue(objJPAEdmAssociationEnd.compare( getAssociationEnd("SOID", 1), getAssociationEnd("String", 1))); assertFalse(objJPAEdmAssociationEnd.compare( getAssociationEnd("String", 2), getAssociationEnd("SOID", 1))); } |
Employee { public String getEmployeeName() { return employeeName; } Employee(final int employeeId, final String name); String getId(); void setEmployeeName(final String employeeName); String getEmployeeName(); void setAge(final int age); int getAge(); void setManager(final Manager manager); Manager getManager(); void setTeam(final Team team); Team getTeam(); void setRoom(final Room room); Room getRoom(); void setImageUri(final String imageUri); String getImageUri(); void setLocation(final Location location); Location getLocation(); void setEntryDate(final Calendar date); Calendar getEntryDate(); void setImageType(final String imageType); String getImageType(); void setImage(final byte[] image); void setImage(final String imageUrl); byte[] getImage(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString(); } | @Test public void testName() { Employee employee1 = new Employee(1, VALUE_NAME); assertEquals(VALUE_NAME, employee1.getEmployeeName()); } |
JPAEdmAssociation extends JPAEdmBaseViewImpl implements
JPAEdmAssociationView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmAssociationBuilder(); } return builder; } JPAEdmAssociation(final JPAEdmAssociationEndView associationEndview,
final JPAEdmEntityTypeView entityTypeView,
final JPAEdmPropertyView propertyView, final int value); JPAEdmAssociation(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override Association getEdmAssociation(); @Override List<Association> getConsistentEdmAssociationList(); @Override Association searchAssociation(final JPAEdmAssociationEndView view); @Override void addJPAEdmAssociationView(final JPAEdmAssociationView associationView,
final JPAEdmAssociationEndView associationEndView); @Override void addJPAEdmRefConstraintView(
final JPAEdmReferentialConstraintView refView); @Override JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView(); @Override int getNumberOfAssociationsWithSimilarEndPoints(
final JPAEdmAssociationEndView view); } | @Test public void testGetBuilder() { assertNotNull(objAssociation.getBuilder()); } |
JPAEdmAssociation extends JPAEdmBaseViewImpl implements
JPAEdmAssociationView { @Override public Association getEdmAssociation() { return currentAssociation; } JPAEdmAssociation(final JPAEdmAssociationEndView associationEndview,
final JPAEdmEntityTypeView entityTypeView,
final JPAEdmPropertyView propertyView, final int value); JPAEdmAssociation(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override Association getEdmAssociation(); @Override List<Association> getConsistentEdmAssociationList(); @Override Association searchAssociation(final JPAEdmAssociationEndView view); @Override void addJPAEdmAssociationView(final JPAEdmAssociationView associationView,
final JPAEdmAssociationEndView associationEndView); @Override void addJPAEdmRefConstraintView(
final JPAEdmReferentialConstraintView refView); @Override JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView(); @Override int getNumberOfAssociationsWithSimilarEndPoints(
final JPAEdmAssociationEndView view); } | @Test public void testGetEdmAssociation() { assertNotNull(objAssociation.getEdmAssociation()); assertEquals(objAssociation.getEdmAssociation().getName(), ASSOCIATION_NAME); } |
JPAEdmAssociation extends JPAEdmBaseViewImpl implements
JPAEdmAssociationView { @Override public List<Association> getConsistentEdmAssociationList() { return consistentAssociatonList; } JPAEdmAssociation(final JPAEdmAssociationEndView associationEndview,
final JPAEdmEntityTypeView entityTypeView,
final JPAEdmPropertyView propertyView, final int value); JPAEdmAssociation(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override Association getEdmAssociation(); @Override List<Association> getConsistentEdmAssociationList(); @Override Association searchAssociation(final JPAEdmAssociationEndView view); @Override void addJPAEdmAssociationView(final JPAEdmAssociationView associationView,
final JPAEdmAssociationEndView associationEndView); @Override void addJPAEdmRefConstraintView(
final JPAEdmReferentialConstraintView refView); @Override JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView(); @Override int getNumberOfAssociationsWithSimilarEndPoints(
final JPAEdmAssociationEndView view); } | @Test public void testGetConsistentEdmAssociationList() { assertTrue(objAssociation.getConsistentEdmAssociationList().size() > 0); } |
JPAEdmAssociation extends JPAEdmBaseViewImpl implements
JPAEdmAssociationView { @Override public void addJPAEdmAssociationView(final JPAEdmAssociationView associationView, final JPAEdmAssociationEndView associationEndView) { if (associationView != null) { currentAssociation = associationView.getEdmAssociation(); associationMap .put(currentAssociation.getName(), currentAssociation); associationEndMap.put(currentAssociation.getName(), associationEndView); addJPAEdmRefConstraintView(associationView .getJPAEdmReferentialConstraintView()); } } JPAEdmAssociation(final JPAEdmAssociationEndView associationEndview,
final JPAEdmEntityTypeView entityTypeView,
final JPAEdmPropertyView propertyView, final int value); JPAEdmAssociation(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override Association getEdmAssociation(); @Override List<Association> getConsistentEdmAssociationList(); @Override Association searchAssociation(final JPAEdmAssociationEndView view); @Override void addJPAEdmAssociationView(final JPAEdmAssociationView associationView,
final JPAEdmAssociationEndView associationEndView); @Override void addJPAEdmRefConstraintView(
final JPAEdmReferentialConstraintView refView); @Override JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView(); @Override int getNumberOfAssociationsWithSimilarEndPoints(
final JPAEdmAssociationEndView view); } | @Test public void testAddJPAEdmAssociationView() { class LocalJPAAssociationView extends JPAEdmTestModelView { @Override public AssociationEnd getEdmAssociationEnd1() { AssociationEnd associationEnd = new AssociationEnd(); associationEnd.setType(new FullQualifiedName( "salesorderprocessing", "SalesOrderHeader")); associationEnd.setRole("SalesOrderHeader"); associationEnd.setMultiplicity(EdmMultiplicity.ONE); return associationEnd; } @Override public AssociationEnd getEdmAssociationEnd2() { AssociationEnd associationEnd = new AssociationEnd(); associationEnd.setType(new FullQualifiedName( "salesorderprocessing", "SalesOrderItem")); associationEnd.setRole("SalesOrderItem"); associationEnd.setMultiplicity(EdmMultiplicity.MANY); return associationEnd; } @Override public Association getEdmAssociation() { Association association = new Association(); association.setEnd1(new AssociationEnd() .setType(new FullQualifiedName("salesorderprocessing", "SalesOrderHeader"))); association.setEnd2(new AssociationEnd() .setType(new FullQualifiedName("salesorderprocessing", "SalesOrderItem"))); return association; } } LocalJPAAssociationView assocViewObj = new LocalJPAAssociationView(); JPAEdmAssociation objLocalAssociation = new JPAEdmAssociation( assocViewObj, assocViewObj, assocViewObj, 1); try { objLocalAssociation.getBuilder().build(); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } objAssociation.addJPAEdmAssociationView(objLocalAssociation, localView); } |
JPAEdmAssociation extends JPAEdmBaseViewImpl implements
JPAEdmAssociationView { @Override public void addJPAEdmRefConstraintView( final JPAEdmReferentialConstraintView refView) { if (refView != null && refView.isExists()) { inconsistentRefConstraintViewList.add(refView); } } JPAEdmAssociation(final JPAEdmAssociationEndView associationEndview,
final JPAEdmEntityTypeView entityTypeView,
final JPAEdmPropertyView propertyView, final int value); JPAEdmAssociation(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override Association getEdmAssociation(); @Override List<Association> getConsistentEdmAssociationList(); @Override Association searchAssociation(final JPAEdmAssociationEndView view); @Override void addJPAEdmAssociationView(final JPAEdmAssociationView associationView,
final JPAEdmAssociationEndView associationEndView); @Override void addJPAEdmRefConstraintView(
final JPAEdmReferentialConstraintView refView); @Override JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView(); @Override int getNumberOfAssociationsWithSimilarEndPoints(
final JPAEdmAssociationEndView view); } | @Test public void testAddJPAEdmRefConstraintView() { localView = new JPAEdmAssociationTest(); objAssociation = new JPAEdmAssociation(localView, localView, localView, 1); try { objAssociation.getBuilder().build(); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } objAssociation.addJPAEdmRefConstraintView(localView); assertTrue(objAssociation.getConsistentEdmAssociationList() .size() > 0); } |
JPAEdmAssociation extends JPAEdmBaseViewImpl implements
JPAEdmAssociationView { @Override public JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView() { if (inconsistentRefConstraintViewList.isEmpty()) { return null; } return inconsistentRefConstraintViewList.get(0); } JPAEdmAssociation(final JPAEdmAssociationEndView associationEndview,
final JPAEdmEntityTypeView entityTypeView,
final JPAEdmPropertyView propertyView, final int value); JPAEdmAssociation(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override Association getEdmAssociation(); @Override List<Association> getConsistentEdmAssociationList(); @Override Association searchAssociation(final JPAEdmAssociationEndView view); @Override void addJPAEdmAssociationView(final JPAEdmAssociationView associationView,
final JPAEdmAssociationEndView associationEndView); @Override void addJPAEdmRefConstraintView(
final JPAEdmReferentialConstraintView refView); @Override JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView(); @Override int getNumberOfAssociationsWithSimilarEndPoints(
final JPAEdmAssociationEndView view); } | @Test public void testGetJPAEdmReferentialConstraintView() { } |
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public boolean isExists() { return roleExists; } JPAEdmReferentialConstraintRole(
final JPAEdmReferentialConstraintRoleView.RoleType roleType,
final JPAEdmEntityTypeView entityTypeView,
final JPAEdmPropertyView propertyView,
final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); } | @Test public void testIsExists() { assertTrue(objJPAEdmReferentialConstraintRole.isExists()); } |
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmRefConstraintRoleBuilder(); } return builder; } JPAEdmReferentialConstraintRole(
final JPAEdmReferentialConstraintRoleView.RoleType roleType,
final JPAEdmEntityTypeView entityTypeView,
final JPAEdmPropertyView propertyView,
final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); } | @Test public void testGetBuilder() { assertNotNull(objJPAEdmReferentialConstraintRole.getBuilder()); }
@Test public void testGetBuilderIdempotent() { JPAEdmBuilder builder1 = objJPAEdmReferentialConstraintRole .getBuilder(); JPAEdmBuilder builder2 = objJPAEdmReferentialConstraintRole .getBuilder(); assertEquals(builder1.hashCode(), builder2.hashCode()); } |
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public RoleType getRoleType() { return roleType; } JPAEdmReferentialConstraintRole(
final JPAEdmReferentialConstraintRoleView.RoleType roleType,
final JPAEdmEntityTypeView entityTypeView,
final JPAEdmPropertyView propertyView,
final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); } | @Test public void testGetRoleTypePrincipal() { assertEquals(objJPAEdmReferentialConstraintRole.getRoleType(), RoleType.PRINCIPAL); } |
Manager extends Employee { public Manager(final int id, final String name) { super(id, name); } Manager(final int id, final String name); List<Employee> getEmployees(); } | @Test public void testManager() { Manager manager = new Manager(1, "Walter Winter"); Employee employee = new Employee(2, "Peter Burke"); Manager manager2 = new Manager(3, "Jonathan Smith"); List<Employee> list = Arrays.asList(manager2, employee, manager); manager.getEmployees().addAll(list); for (Employee emp : list) { emp.setManager(manager); } assertEquals(list, manager.getEmployees()); assertEquals(manager, employee.getManager()); } |
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public ReferentialConstraintRole getEdmReferentialConstraintRole() { return currentRole; } JPAEdmReferentialConstraintRole(
final JPAEdmReferentialConstraintRoleView.RoleType roleType,
final JPAEdmEntityTypeView entityTypeView,
final JPAEdmPropertyView propertyView,
final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); } | @Test public void testGetEdmReferentialConstraintRole() { try { objJPAEdmReferentialConstraintRole.getBuilder().build(); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } assertNotNull(objJPAEdmReferentialConstraintRole .getEdmReferentialConstraintRole()); } |
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public String getJPAColumnName() { return null; } JPAEdmReferentialConstraintRole(
final JPAEdmReferentialConstraintRoleView.RoleType roleType,
final JPAEdmEntityTypeView entityTypeView,
final JPAEdmPropertyView propertyView,
final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); } | @Test public void testGetJPAColumnName() { assertNull(objJPAEdmReferentialConstraintRole.getJPAColumnName()); } |
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public String getEdmEntityTypeName() { return null; } JPAEdmReferentialConstraintRole(
final JPAEdmReferentialConstraintRoleView.RoleType roleType,
final JPAEdmEntityTypeView entityTypeView,
final JPAEdmPropertyView propertyView,
final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); } | @Test public void testGetEdmEntityTypeName() { assertNull(objJPAEdmReferentialConstraintRole.getEdmEntityTypeName()); } |
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public String getEdmAssociationName() { return null; } JPAEdmReferentialConstraintRole(
final JPAEdmReferentialConstraintRoleView.RoleType roleType,
final JPAEdmEntityTypeView entityTypeView,
final JPAEdmPropertyView propertyView,
final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); } | @Test public void testGetEdmAssociationName() { assertNull(objJPAEdmReferentialConstraintRole.getEdmAssociationName()); } |
JPAEdmEntityType extends JPAEdmBaseViewImpl implements
JPAEdmEntityTypeView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmEntityTypeBuilder(); } return builder; } JPAEdmEntityType(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override EntityType getEdmEntityType(); @Override javax.persistence.metamodel.EntityType<?> getJPAEntityType(); @Override List<EntityType> getConsistentEdmEntityTypes(); @Override EntityType searchEdmEntityType(final String jpaEntityTypeName); } | @Test public void testGetBuilder() { assertNotNull(objJPAEdmEntityType.getBuilder()); }
@Test public void testGetBuilderIdempotent() { JPAEdmBuilder builder1 = objJPAEdmEntityType.getBuilder(); JPAEdmBuilder builder2 = objJPAEdmEntityType.getBuilder(); assertEquals(builder1.hashCode(), builder2.hashCode()); } |
JPAEdmEntityType extends JPAEdmBaseViewImpl implements
JPAEdmEntityTypeView { @Override public EntityType getEdmEntityType() { return currentEdmEntityType; } JPAEdmEntityType(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override EntityType getEdmEntityType(); @Override javax.persistence.metamodel.EntityType<?> getJPAEntityType(); @Override List<EntityType> getConsistentEdmEntityTypes(); @Override EntityType searchEdmEntityType(final String jpaEntityTypeName); } | @Test public void testGetEdmEntityType() { assertNotNull(objJPAEdmEntityType.getEdmEntityType()); assertNotNull(objJPAEdmEntityType.getEdmEntityType().getKey()); } |
JPAEdmEntityType extends JPAEdmBaseViewImpl implements
JPAEdmEntityTypeView { @Override public javax.persistence.metamodel.EntityType<?> getJPAEntityType() { return currentJPAEntityType; } JPAEdmEntityType(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override EntityType getEdmEntityType(); @Override javax.persistence.metamodel.EntityType<?> getJPAEntityType(); @Override List<EntityType> getConsistentEdmEntityTypes(); @Override EntityType searchEdmEntityType(final String jpaEntityTypeName); } | @Test public void testGetJPAEntityType() { assertNotNull(objJPAEdmEntityType.getJPAEntityType()); } |
JPAEdmEntityType extends JPAEdmBaseViewImpl implements
JPAEdmEntityTypeView { @Override public List<EntityType> getConsistentEdmEntityTypes() { return consistentEntityTypes; } JPAEdmEntityType(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override EntityType getEdmEntityType(); @Override javax.persistence.metamodel.EntityType<?> getJPAEntityType(); @Override List<EntityType> getConsistentEdmEntityTypes(); @Override EntityType searchEdmEntityType(final String jpaEntityTypeName); } | @Test public void testGetConsistentEdmEntityTypes() { assertTrue(objJPAEdmEntityType.getConsistentEdmEntityTypes().size() > 0); } |
JPAEdmEntityType extends JPAEdmBaseViewImpl implements
JPAEdmEntityTypeView { @Override public EntityType searchEdmEntityType(final String jpaEntityTypeName) { return consistentEntityTypeMap.get(jpaEntityTypeName); } JPAEdmEntityType(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override EntityType getEdmEntityType(); @Override javax.persistence.metamodel.EntityType<?> getJPAEntityType(); @Override List<EntityType> getConsistentEdmEntityTypes(); @Override EntityType searchEdmEntityType(final String jpaEntityTypeName); } | @Test public void testSearchEdmEntityType() { assertNotNull(objJPAEdmEntityType.searchEdmEntityType("SalesOrderHeader")); } |
Manager extends Employee { public List<Employee> getEmployees() { return employees; } Manager(final int id, final String name); List<Employee> getEmployees(); } | @Test public void testRoom() { Employee manager = new Manager(1, null); Room room = new Room(1, null); room.getEmployees().add(manager); manager.setRoom(room); assertEquals(room, manager.getRoom()); assertEquals(manager, room.getEmployees().get(0)); }
@Test public void testTeam() { Employee manager = new Manager(1, null); List<Employee> list = Arrays.asList(manager); Team team = new Team(1, TEAM_NAME); team.getEmployees().add(manager); manager.setTeam(team); assertEquals(team, manager.getTeam()); assertEquals(list, team.getEmployees()); }
@Test public void testEmployees() { Manager manager = new Manager(1, null); Employee employee1 = new Employee(2, null); Employee employee2 = new Employee(3, null); List<Employee> employeesList = Arrays.asList(employee1, employee2); manager.getEmployees().addAll(employeesList); for (Employee emp : employeesList) { emp.setManager(manager); } List<Employee> testList = manager.getEmployees(); assertEquals(testList, employeesList); assertEquals(manager, employee1.getManager()); } |
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements
JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); } | @Test public void testFunctionImportBasic() { VARIANT = 0; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport .getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 1); for (FunctionImport functionImport : functionImportList) { assertEquals(functionImport.getName(), "Method1"); assertNotNull(functionImport.getMapping()); Mapping mapping = new Mapping(); mapping.setInternalName("method1"); assertEquals(mapping.getInternalName(), functionImport.getMapping() .getInternalName()); ReturnType returnType = functionImport.getReturnType(); assertNotNull(returnType); assertEquals(EdmMultiplicity.MANY, returnType.getMultiplicity()); List<FunctionImportParameter> funcImpList = functionImport .getParameters(); assertEquals(2, funcImpList.size()); assertEquals("Param1", funcImpList.get(0).getName()); assertEquals(EdmSimpleTypeKind.String, funcImpList.get(0).getType()); assertEquals(Mode.IN.toString(), funcImpList.get(0).getMode()); assertEquals("Param3", funcImpList.get(1).getName()); assertEquals(EdmSimpleTypeKind.Double, funcImpList.get(1).getType()); assertEquals(Mode.IN.toString(), funcImpList.get(1).getMode()); } }
@Test public void testFunctionImportNoSuchMethod() { VARIANT = 1; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport .getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 0); }
@Test public void testFunctionImportAllMethods() { VARIANT = 2; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport .getConsistentFunctionImportList(); assertEquals(METHOD_COUNT, functionImportList.size()); }
@Test public void testFunctionImportNoName() { VARIANT = 3; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport .getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 1); FunctionImport functionImport = functionImportList.get(0); assertEquals(functionImport.getName(), "method3"); assertNotNull(functionImport.getMapping()); ReturnType returnType = functionImport.getReturnType(); assertNotNull(returnType); assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity()); assertEquals(returnType.getTypeName().toString(), EdmSimpleTypeKind.Int32.getFullQualifiedName().toString()); }
@Test public void testNoReturnType() { VARIANT = 4; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport .getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 0); }
@Test public void testFunctionImportEntityTypeSingleReturn() { VARIANT = 7; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport .getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 1); FunctionImport functionImport = functionImportList.get(0); assertEquals(functionImport.getName(), "method7"); assertNotNull(functionImport.getMapping()); JPAEdmMapping mapping = (JPAEdmMapping) functionImport.getMapping(); assertEquals(JPACustomProcessorMock.class, mapping.getJPAType()); ReturnType returnType = functionImport.getReturnType(); assertNotNull(returnType); assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity()); assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "." + JPACustomProcessorMock.edmName); }
@Test public void testFunctionImportComplexType() { VARIANT = 9; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport .getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 1); FunctionImport functionImport = functionImportList.get(0); assertEquals(functionImport.getName(), "method9"); assertNotNull(functionImport.getMapping()); ReturnType returnType = functionImport.getReturnType(); assertNotNull(returnType); assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity()); assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "." + JPACustomProcessorMock.edmName); }
@Test public void testFunctionImportComplexTypeMany() { VARIANT = 10; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport .getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 1); FunctionImport functionImport = functionImportList.get(0); assertEquals(functionImport.getName(), "method10"); assertNotNull(functionImport.getMapping()); ReturnType returnType = functionImport.getReturnType(); assertNotNull(returnType); assertEquals(EdmMultiplicity.MANY, returnType.getMultiplicity()); assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "." + JPACustomProcessorMock.edmName); }
@Test public void testFunctionImportParamFacets() { VARIANT = 14; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport .getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 1); List<FunctionImportParameter> funcImpParamList = functionImportList .get(0).getParameters(); EdmFacets facets = funcImpParamList.get(0).getFacets(); assertNotNull(facets); assertEquals(2, facets.getMaxLength().intValue()); assertEquals(true, facets.isNullable()); facets = funcImpParamList.get(1).getFacets(); assertNotNull(facets); assertEquals(false, facets.isNullable()); assertEquals(10, facets.getPrecision().intValue()); assertEquals(2, facets.getScale().intValue()); }
@Test public void testFunctionImportParamFacetsDefault() { VARIANT = 15; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport .getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 1); List<FunctionImportParameter> funcImpParamList = functionImportList .get(0).getParameters(); EdmFacets facets = funcImpParamList.get(0).getFacets(); assertNotNull(facets); assertNull(facets.getMaxLength()); assertEquals(false, facets.isNullable()); assertNull(facets.getPrecision()); assertNull(facets.getScale()); }
@Test public void testNoFunctionImport() { VARIANT = 99; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport .getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 0); } |
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements
JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); } | @Test public void testNoEntitySet() { VARIANT = 5; try { jpaEdmfunctionImport.getBuilder().build(); fail("Exception Expected"); } catch (ODataJPAModelException e) { assertEquals(ODataJPAModelException.FUNC_ENTITYSET_EXP.getKey(), e .getMessageReference().getKey()); } catch (ODataJPARuntimeException e) { fail("Model Exception Expected"); } }
@Test public void testNoReturnTypeButAnnotated() { VARIANT = 6; try { jpaEdmfunctionImport.getBuilder().build(); fail("Exception Expected"); } catch (ODataJPAModelException e) { assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e.getMessageReference().getKey()); } catch (ODataJPARuntimeException e) { fail("Model Exception Expected"); } }
@Test public void testFunctionImportEntityTypeInvalid() { VARIANT = 8; try { jpaEdmfunctionImport.getBuilder().build(); fail("Exception Expected"); } catch (ODataJPAModelException e) { assertEquals( ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND .getKey(), e.getMessageReference().getKey()); } catch (ODataJPARuntimeException e) { fail("Model Exception Expected"); } }
@Test public void testFunctionImportComplexTypeInvalid() { VARIANT = 11; try { jpaEdmfunctionImport.getBuilder().build(); fail("Exception Expected"); } catch (ODataJPAModelException e) { assertEquals( ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND .getKey(), e.getMessageReference().getKey()); } catch (ODataJPARuntimeException e) { fail("Model Exception Expected"); } }
@Test public void testFunctionImportScalarTypeInvalid() { VARIANT = 12; try { jpaEdmfunctionImport.getBuilder().build(); fail("Exception Expected"); } catch (ODataJPAModelException e) { assertEquals(ODataJPAModelException.TYPE_NOT_SUPPORTED.getKey(), e .getMessageReference().getKey()); } catch (ODataJPARuntimeException e) { fail("Model Exception Expected"); } }
@Test public void testFunctionImportParamNoName() { VARIANT = 13; try { jpaEdmfunctionImport.getBuilder().build(); fail("Exception Expected"); } catch (ODataJPAModelException e) { assertEquals(ODataJPAModelException.FUNC_PARAM_NAME_EXP.getKey(), e .getMessageReference().getKey()); } catch (ODataJPARuntimeException e) { fail("Model Exception Expected"); } }
@Test public void testWrongReturnTypeScalar() { VARIANT = 16; try { jpaEdmfunctionImport.getBuilder().build(); fail("Exception Expected"); } catch (ODataJPAModelException e) { assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e .getMessageReference().getKey()); } catch (ODataJPARuntimeException e) { fail("Model Exception Expected"); } }
@Test public void testWrongReturnTypeComplex() { VARIANT = 17; try { jpaEdmfunctionImport.getBuilder().build(); fail("Exception Expected"); } catch (ODataJPAModelException e) { assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e .getMessageReference().getKey()); } catch (ODataJPARuntimeException e) { fail("Model Exception Expected"); } }
@Test public void testGetBuilderIdempotent() { JPAEdmFunctionImport jpaEdmfunctionImport = new JPAEdmFunctionImport( this); JPAEdmBuilder builder1 = jpaEdmfunctionImport.getBuilder(); JPAEdmBuilder builder2 = jpaEdmfunctionImport.getBuilder(); assertEquals(builder1.hashCode(), builder2.hashCode()); } |
JPAEdmProperty extends JPAEdmBaseViewImpl implements
JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmPropertyBuilder(); } return builder; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView,
final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); } | @Test public void testGetBuilder() { assertNotNull(objJPAEdmProperty.getBuilder()); objJPAEdmPropertyTest = new JPAEdmPropertyTest(); objJPAEdmProperty = new JPAEdmProperty(objJPAEdmPropertyTest, objJPAEdmPropertyTest); try { objJPAEdmProperty.getBuilder().build(); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
@Test public void testGetBuilderIdempotent() { JPAEdmBuilder builder1 = objJPAEdmProperty.getBuilder(); JPAEdmBuilder builder2 = objJPAEdmProperty.getBuilder(); assertEquals(builder1.hashCode(), builder2.hashCode()); }
@Test public void testBuildManyToOne() { ATTRIBUTE_TYPE = 3; objJPAEdmPropertyTest = new JPAEdmPropertyTest(); objJPAEdmProperty = new JPAEdmProperty(objJPAEdmPropertyTest); try { objJPAEdmProperty.getBuilder().build(); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } ATTRIBUTE_TYPE = 1; objJPAEdmPropertyTest = new JPAEdmPropertyTest(); objJPAEdmProperty = new JPAEdmProperty(objJPAEdmPropertyTest); try { objJPAEdmProperty.getBuilder().build(); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } } |
JPAEdmProperty extends JPAEdmBaseViewImpl implements
JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public List<Property> getEdmPropertyList() { return properties; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView,
final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); } | @Test public void testGetPropertyList() { assertNotNull(objJPAEdmProperty.getEdmPropertyList()); assertTrue(objJPAEdmProperty.getEdmPropertyList().size() > 0); } |
JPAEdmProperty extends JPAEdmBaseViewImpl implements
JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmKeyView getJPAEdmKeyView() { return keyView; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView,
final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); } | @Test public void testGetJPAEdmKeyView() { assertNotNull(objJPAEdmProperty.getJPAEdmKeyView()); } |
JPAEdmProperty extends JPAEdmBaseViewImpl implements
JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public SimpleProperty getEdmSimpleProperty() { return currentSimpleProperty; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView,
final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); } | @Test public void testGetSimpleProperty() { assertNotNull(objJPAEdmProperty.getEdmSimpleProperty()); } |
JPAEdmProperty extends JPAEdmBaseViewImpl implements
JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public Attribute<?, ?> getJPAAttribute() { return currentAttribute; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView,
final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); } | @Test public void testGetJPAAttribute() { assertNotNull(objJPAEdmProperty.getJPAAttribute()); } |
JPAEdmProperty extends JPAEdmBaseViewImpl implements
JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public ComplexProperty getEdmComplexProperty() { return currentComplexProperty; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView,
final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); } | @Test public void testGetEdmComplexProperty() { assertNull(objJPAEdmProperty.getEdmComplexProperty()); } |
JPAEdmProperty extends JPAEdmBaseViewImpl implements
JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView() { return navigationPropertyView; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView,
final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); } | @Test public void testGetJPAEdmNavigationPropertyView() { assertNotNull(objJPAEdmProperty.getJPAEdmNavigationPropertyView()); } |
JPAEdmKey extends JPAEdmBaseViewImpl implements JPAEdmKeyView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmKeyBuider(); } return builder; } JPAEdmKey(final JPAEdmProperty view); JPAEdmKey(final JPAEdmComplexTypeView complexTypeView,
final JPAEdmPropertyView propertyView); @Override JPAEdmBuilder getBuilder(); @Override Key getEdmKey(); } | @Test public void testGetBuilderIdempotent() { JPAEdmBuilder builder1 = keyView.getBuilder(); JPAEdmBuilder builder2 = keyView.getBuilder(); assertEquals(builder1.hashCode(), builder2.hashCode()); } |
JPAProcessorImpl implements JPAProcessor { @SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; } JPAProcessorImpl(final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") @Override List<Object> process(final GetFunctionImportUriInfo uriParserResultView); @SuppressWarnings("unchecked") @Override List<T> process(final GetEntitySetUriInfo uriParserResultView); @Override Object process(GetEntityUriInfo uriParserResultView); @Override long process(final GetEntitySetCountUriInfo resultsView); @Override long process(final GetEntityCountUriInfo resultsView); @Override List<T> process(final PostUriInfo createView, final InputStream content,
final String requestedContentType); @Override List<T> process(final PostUriInfo createView, final Map<String, Object> content); @Override Object process(final PutMergePatchUriInfo updateView,
final InputStream content, final String requestContentType); @Override Object process(final PutMergePatchUriInfo updateView, final Map<String, Object> content); Object processUpdate(PutMergePatchUriInfo updateView,
final InputStream content, final Map<String, Object> properties, final String requestContentType); @Override Object process(DeleteUriInfo uriParserResultView, final String contentType); @Override Object process(final GetEntityLinkUriInfo uriParserResultView); @Override List<T> process(final GetEntitySetLinksUriInfo uriParserResultView); @Override void process(final PostUriInfo uriInfo,
final InputStream content, final String requestContentType, final String contentType); @Override void process(final PutMergePatchUriInfo putUriInfo,
final InputStream content, final String requestContentType, final String contentType); } | @Test public void testProcessGetEntitySetCountUriInfo() { try { Assert.assertEquals(11, objJPAProcessorImpl.process(getEntitySetCountUriInfo())); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
@Test public void testProcessGetEntityCountUriInfo() { try { Assert.assertEquals(11, objJPAProcessorImpl.process(getEntityCountUriInfo())); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
@Test public void testProcessGetEntitySetUriInfo() { try { Assert.assertNotNull(objJPAProcessorImpl.process(getEntitySetUriInfo())); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
@Test public void testProcessDeleteUriInfo() { try { Assert.assertNotNull(objJPAProcessorImpl.process(getDeletetUriInfo(), "application/xml")); Assert.assertEquals(new Address(), objJPAProcessorImpl.process(getDeletetUriInfo(), "application/xml")); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
@Test public void testProcessDeleteUriInfoNegative() { try { Assert.assertNotNull(objJPAProcessorImpl.process(getDeletetUriInfo(), "application/xml")); Assert.assertNotSame(new Object(), objJPAProcessorImpl.process(getDeletetUriInfo(), "application/xml")); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } } |
ODataJPAResponseBuilder { private static List<EdmNavigationProperty> constructListofNavProperty( final List<ArrayList<NavigationPropertySegment>> expandList) { List<EdmNavigationProperty> navigationPropertyList = new ArrayList<EdmNavigationProperty>(); for (ArrayList<NavigationPropertySegment> navpropSegment : expandList) { navigationPropertyList.add(navpropSegment.get(0) .getNavigationProperty()); } return navigationPropertyList; } static ODataResponse build(final List<T> jpaEntities,
final GetEntitySetUriInfo resultsView, final String contentType,
final ODataJPAContext odataJPAContext); static ODataResponse build(final Object jpaEntity,
final GetEntityUriInfo resultsView, final String contentType,
final ODataJPAContext oDataJPAContext); static ODataResponse build(final long jpaEntityCount,
final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") static ODataResponse build(final List<Object> createdObjectList,
final PostUriInfo uriInfo, final String contentType,
final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object updatedObject,
final PutMergePatchUriInfo putUriInfo); static ODataResponse build(final Object deletedObject,
final DeleteUriInfo deleteUriInfo); static ODataResponse build(final Object result,
final GetFunctionImportUriInfo resultsView); static ODataResponse build(final List<Object> resultList,
final GetFunctionImportUriInfo resultsView, final String contentType,
final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object jpaEntity,
final GetEntityLinkUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final List<T> jpaEntities,
final GetEntitySetLinksUriInfo resultsView, final String contentType,
final ODataJPAContext oDataJPAContext); } | @SuppressWarnings("unchecked") @Test public void testConstructListofNavProperty() { List<ArrayList<NavigationPropertySegment>> expand = new ArrayList<ArrayList<NavigationPropertySegment>>(); ArrayList<NavigationPropertySegment> navPropList1 = new ArrayList<NavigationPropertySegment>(); navPropList1.add(getNavigationPropertySegment("DemoNavigationProperties11")); navPropList1.add(getNavigationPropertySegment("DemoNavigationProperties12")); expand.add(navPropList1); ArrayList<NavigationPropertySegment> navPropList2 = new ArrayList<NavigationPropertySegment>(); navPropList2.add(getNavigationPropertySegment("DemoNavigationProperties21")); navPropList2.add(getNavigationPropertySegment("DemoNavigationProperties22")); expand.add(navPropList2); Class<?> clazz = ODataJPAResponseBuilder.class; Object[] actualParameters = { expand }; Class<?>[] formalParameters = { List.class }; List<EdmNavigationProperty> navigationProperties = null; try { ODataJPAResponseBuilder responseBuilder = (ODataJPAResponseBuilder) clazz .newInstance(); Method method = clazz.getDeclaredMethod( "constructListofNavProperty", formalParameters); method.setAccessible(true); navigationProperties = (List<EdmNavigationProperty>) method.invoke( responseBuilder, actualParameters); assertEquals("DemoNavigationProperties21", navigationProperties.get(1).getName()); assertEquals("DemoNavigationProperties11", navigationProperties.get(0).getName()); } catch (SecurityException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (NoSuchMethodException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (IllegalArgumentException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (IllegalAccessException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (InvocationTargetException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (InstantiationException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (EdmException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } } |
ODataJPAResponseBuilder { public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; } static ODataResponse build(final List<T> jpaEntities,
final GetEntitySetUriInfo resultsView, final String contentType,
final ODataJPAContext odataJPAContext); static ODataResponse build(final Object jpaEntity,
final GetEntityUriInfo resultsView, final String contentType,
final ODataJPAContext oDataJPAContext); static ODataResponse build(final long jpaEntityCount,
final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") static ODataResponse build(final List<Object> createdObjectList,
final PostUriInfo uriInfo, final String contentType,
final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object updatedObject,
final PutMergePatchUriInfo putUriInfo); static ODataResponse build(final Object deletedObject,
final DeleteUriInfo deleteUriInfo); static ODataResponse build(final Object result,
final GetFunctionImportUriInfo resultsView); static ODataResponse build(final List<Object> resultList,
final GetFunctionImportUriInfo resultsView, final String contentType,
final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object jpaEntity,
final GetEntityLinkUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final List<T> jpaEntities,
final GetEntitySetLinksUriInfo resultsView, final String contentType,
final ODataJPAContext oDataJPAContext); } | @Test public void testBuildListOfTGetEntitySetUriInfoStringODataJPAContext() { try { assertNotNull(ODataJPAResponseBuilder.build(getJPAEntities(), getResultsView(), "application/xml", getODataJPAContext())); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
@Test public void testBuildNegatives() { try { EntityType entity = new EntityType(); entity.setName("SalesOrderHeader"); try { assertNotNull(ODataJPAResponseBuilder.build(getEntity(), getLocalGetURIInfo(), "xml", getODataJPAContext())); } catch (ODataNotFoundException e) { assertTrue(true); } } catch (ODataJPARuntimeException e) { assertTrue(true); } try { assertNotNull(ODataJPAResponseBuilder.build(getJPAEntities(), getResultsView(), "xml", getODataJPAContext())); } catch (ODataJPARuntimeException e) { assertTrue(true); } }
@Test public void testBuildObjectGetEntityUriInfoStringODataJPAContext() throws ODataNotFoundException { try { assertNotNull(ODataJPAResponseBuilder.build(new SalesOrderHeader(2, 10), getLocalGetURIInfo(), "application/xml", getODataJPAContext())); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
@Test public void testBuildNullSelects() { try { ODataJPAResponseBuilder.build(getJPAEntities(), getResultsViewWithNullSelects(), "xml", getODataJPAContext()); } catch (ODataJPARuntimeException e) { assertTrue(true); } catch (Exception e) { assertTrue(true); } }
@Test public void testBuildGetCount() { ODataResponse objODataResponse = null; try { objODataResponse = ODataJPAResponseBuilder.build(1, getODataJPAContext()); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } assertNotNull(objODataResponse); } |
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType) throws ODataException { Object jpaEntity = jpaProcessor.process(uriParserResultView); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView, contentType, oDataJPAContext); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); @Override ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView,
final String contentType); @Override ODataResponse readEntity(final GetEntityUriInfo uriParserResultView,
final String contentType); @Override ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView,
final String contentType); @Override ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo,
final String contentType); @Override ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content,
final String requestContentType, final String contentType); @Override ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView,
final InputStream content, final String requestContentType, final boolean merge,
final String contentType); @Override ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView,
final String contentType); @Override ODataResponse executeFunctionImport(
final GetFunctionImportUriInfo uriParserResultView,
final String contentType); @Override ODataResponse executeFunctionImportValue(
final GetFunctionImportUriInfo uriParserResultView,
final String contentType); @Override ODataResponse readEntityLink(
final GetEntityLinkUriInfo uriParserResultView,
final String contentType); @Override ODataResponse readEntityLinks(
final GetEntitySetLinksUriInfo uriParserResultView,
final String contentType); @Override ODataResponse createEntityLink(
final PostUriInfo uriParserResultView, final InputStream content,
final String requestContentType, final String contentType); @Override ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView,
final InputStream content, final String requestContentType, final String contentType); } | @Test public void testReadEntitySetGetEntitySetUriInfoString() { try { GetEntityUriInfo getEntityView = getEntityUriInfo(); Assert.assertNotNull(objODataJPAProcessorDefault.readEntity(getEntityView, HttpContentType.APPLICATION_XML)); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPARuntimeException e1) { assertTrue(true); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } } |
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType) throws ODataException { long jpaEntityCount = jpaProcessor.process(uriParserResultView); ODataResponse oDataResponse = ODataJPAResponseBuilder.build( jpaEntityCount, oDataJPAContext); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); @Override ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView,
final String contentType); @Override ODataResponse readEntity(final GetEntityUriInfo uriParserResultView,
final String contentType); @Override ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView,
final String contentType); @Override ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo,
final String contentType); @Override ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content,
final String requestContentType, final String contentType); @Override ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView,
final InputStream content, final String requestContentType, final boolean merge,
final String contentType); @Override ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView,
final String contentType); @Override ODataResponse executeFunctionImport(
final GetFunctionImportUriInfo uriParserResultView,
final String contentType); @Override ODataResponse executeFunctionImportValue(
final GetFunctionImportUriInfo uriParserResultView,
final String contentType); @Override ODataResponse readEntityLink(
final GetEntityLinkUriInfo uriParserResultView,
final String contentType); @Override ODataResponse readEntityLinks(
final GetEntitySetLinksUriInfo uriParserResultView,
final String contentType); @Override ODataResponse createEntityLink(
final PostUriInfo uriParserResultView, final InputStream content,
final String requestContentType, final String contentType); @Override ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView,
final InputStream content, final String requestContentType, final String contentType); } | @Test public void testcountEntitySet() { try { Assert.assertNotNull(objODataJPAProcessorDefault.countEntitySet(getEntitySetCountUriInfo(), HttpContentType.APPLICATION_XML)); Assert.assertEquals(TEXT_PLAIN_CHARSET_UTF_8, objODataJPAProcessorDefault.countEntitySet(getEntitySetCountUriInfo(), HttpContentType.APPLICATION_XML).getHeader(STR_CONTENT_TYPE)); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (Exception e) { assertTrue(true); } } |
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType) throws ODataException { long jpaEntityCount = jpaProcessor.process(uriInfo); ODataResponse oDataResponse = ODataJPAResponseBuilder.build( jpaEntityCount, oDataJPAContext); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); @Override ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView,
final String contentType); @Override ODataResponse readEntity(final GetEntityUriInfo uriParserResultView,
final String contentType); @Override ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView,
final String contentType); @Override ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo,
final String contentType); @Override ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content,
final String requestContentType, final String contentType); @Override ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView,
final InputStream content, final String requestContentType, final boolean merge,
final String contentType); @Override ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView,
final String contentType); @Override ODataResponse executeFunctionImport(
final GetFunctionImportUriInfo uriParserResultView,
final String contentType); @Override ODataResponse executeFunctionImportValue(
final GetFunctionImportUriInfo uriParserResultView,
final String contentType); @Override ODataResponse readEntityLink(
final GetEntityLinkUriInfo uriParserResultView,
final String contentType); @Override ODataResponse readEntityLinks(
final GetEntitySetLinksUriInfo uriParserResultView,
final String contentType); @Override ODataResponse createEntityLink(
final PostUriInfo uriParserResultView, final InputStream content,
final String requestContentType, final String contentType); @Override ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView,
final InputStream content, final String requestContentType, final String contentType); } | @Test public void testExistsEntity() { try { Assert.assertNotNull(objODataJPAProcessorDefault.existsEntity(getEntityCountCountUriInfo(), HttpContentType.APPLICATION_XML)); Assert.assertEquals(TEXT_PLAIN_CHARSET_UTF_8, objODataJPAProcessorDefault.existsEntity(getEntityCountCountUriInfo(), HttpContentType.APPLICATION_XML).getHeader(STR_CONTENT_TYPE)); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (Exception e) { assertTrue(true); } } |
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType) throws ODataException { Object deletedObj = jpaProcessor.process(uriParserResultView, contentType); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(deletedObj, uriParserResultView); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); @Override ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView,
final String contentType); @Override ODataResponse readEntity(final GetEntityUriInfo uriParserResultView,
final String contentType); @Override ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView,
final String contentType); @Override ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo,
final String contentType); @Override ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content,
final String requestContentType, final String contentType); @Override ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView,
final InputStream content, final String requestContentType, final boolean merge,
final String contentType); @Override ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView,
final String contentType); @Override ODataResponse executeFunctionImport(
final GetFunctionImportUriInfo uriParserResultView,
final String contentType); @Override ODataResponse executeFunctionImportValue(
final GetFunctionImportUriInfo uriParserResultView,
final String contentType); @Override ODataResponse readEntityLink(
final GetEntityLinkUriInfo uriParserResultView,
final String contentType); @Override ODataResponse readEntityLinks(
final GetEntitySetLinksUriInfo uriParserResultView,
final String contentType); @Override ODataResponse createEntityLink(
final PostUriInfo uriParserResultView, final InputStream content,
final String requestContentType, final String contentType); @Override ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView,
final InputStream content, final String requestContentType, final String contentType); } | @Test public void testDeleteEntity() { try { Assert.assertNotNull(objODataJPAProcessorDefault.deleteEntity(getDeletetUriInfo(), HttpContentType.APPLICATION_XML)); Assert.assertEquals(TEXT_PLAIN_CHARSET_UTF_8, objODataJPAProcessorDefault.countEntitySet(getEntitySetCountUriInfo(), HttpContentType.APPLICATION_XML).getHeader(STR_CONTENT_TYPE)); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } } |
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType) throws ODataException { List<Object> createdJpaEntityList = jpaProcessor.process(uriParserResultView, content, requestContentType); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(createdJpaEntityList, uriParserResultView, contentType, oDataJPAContext); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); @Override ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView,
final String contentType); @Override ODataResponse readEntity(final GetEntityUriInfo uriParserResultView,
final String contentType); @Override ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView,
final String contentType); @Override ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo,
final String contentType); @Override ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content,
final String requestContentType, final String contentType); @Override ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView,
final InputStream content, final String requestContentType, final boolean merge,
final String contentType); @Override ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView,
final String contentType); @Override ODataResponse executeFunctionImport(
final GetFunctionImportUriInfo uriParserResultView,
final String contentType); @Override ODataResponse executeFunctionImportValue(
final GetFunctionImportUriInfo uriParserResultView,
final String contentType); @Override ODataResponse readEntityLink(
final GetEntityLinkUriInfo uriParserResultView,
final String contentType); @Override ODataResponse readEntityLinks(
final GetEntitySetLinksUriInfo uriParserResultView,
final String contentType); @Override ODataResponse createEntityLink(
final PostUriInfo uriParserResultView, final InputStream content,
final String requestContentType, final String contentType); @Override ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView,
final InputStream content, final String requestContentType, final String contentType); } | @Test public void testCreateEntity() { try { Assert.assertNotNull(objODataJPAProcessorDefault.createEntity(getPostUriInfo(), getMockedInputStreamContent(), HttpContentType.APPLICATION_XML, HttpContentType.APPLICATION_XML)); } catch (ODataException e) { Assert.assertTrue(true); } } |
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final boolean merge, final String contentType) throws ODataException { Object jpaEntity = jpaProcessor.process(uriParserResultView, content, requestContentType); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); @Override ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView,
final String contentType); @Override ODataResponse readEntity(final GetEntityUriInfo uriParserResultView,
final String contentType); @Override ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView,
final String contentType); @Override ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo,
final String contentType); @Override ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content,
final String requestContentType, final String contentType); @Override ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView,
final InputStream content, final String requestContentType, final boolean merge,
final String contentType); @Override ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView,
final String contentType); @Override ODataResponse executeFunctionImport(
final GetFunctionImportUriInfo uriParserResultView,
final String contentType); @Override ODataResponse executeFunctionImportValue(
final GetFunctionImportUriInfo uriParserResultView,
final String contentType); @Override ODataResponse readEntityLink(
final GetEntityLinkUriInfo uriParserResultView,
final String contentType); @Override ODataResponse readEntityLinks(
final GetEntitySetLinksUriInfo uriParserResultView,
final String contentType); @Override ODataResponse createEntityLink(
final PostUriInfo uriParserResultView, final InputStream content,
final String requestContentType, final String contentType); @Override ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView,
final InputStream content, final String requestContentType, final String contentType); } | @Test public void testUpdateEntity() { try { Assert.assertNotNull(objODataJPAProcessorDefault.updateEntity(getPutUriInfo(), getMockedInputStreamContent(), HttpContentType.APPLICATION_XML, false, HttpContentType.APPLICATION_XML)); } catch (ODataException e) { Assert.assertTrue(true); } } |
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias); static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields); static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression, final String tableAlias); static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias); static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(final List<EdmProperty> edmPropertylist, final String tableAlias); static final String EMPTY; static Integer methodFlag; } | @Test public void testParseWhereExpression() { try { String parsedStr = ODataJPATestConstants.EMPTY_STRING; parsedStr = ODataExpressionParser.parseToJPAWhereExpression( getBinaryExpressionMockedObj(BinaryOperator.EQ, ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_1), TABLE_ALIAS); assertEquals(EXPECTED_STR_1, parsedStr); parsedStr = ODataJPATestConstants.EMPTY_STRING; CommonExpression exp1 = getBinaryExpressionMockedObj( BinaryOperator.GE, ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_1); CommonExpression exp2 = getBinaryExpressionMockedObj( BinaryOperator.NE, ExpressionKind.PROPERTY, SALES_ABC, SAMPLE_DATA_XYZ); parsedStr = ODataExpressionParser.parseToJPAWhereExpression( getBinaryExpression(exp1, BinaryOperator.AND, exp2), TABLE_ALIAS); assertEquals(EXPECTED_STR_2, parsedStr); } catch (EdmException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
@Test public void testMoreThanOneBinaryExpression() { String parsedStr = ODataJPATestConstants.EMPTY_STRING; CommonExpression exp1 = getBinaryExpressionMockedObj(BinaryOperator.GE, ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_1); CommonExpression exp2 = getBinaryExpressionMockedObj(BinaryOperator.NE, ExpressionKind.PROPERTY, SALES_ABC, SAMPLE_DATA_XYZ); try { parsedStr = ODataExpressionParser.parseToJPAWhereExpression( getBinaryExpression(exp1, BinaryOperator.AND, exp2), TABLE_ALIAS); assertEquals(EXPECTED_STR_2, parsedStr); parsedStr = ODataExpressionParser .parseToJPAWhereExpression( getBinaryExpression(exp1, BinaryOperator.OR, exp2), TABLE_ALIAS); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } assertEquals(EXPECTED_STR_3, parsedStr); }
@Test public void testParseFilterExpression() { try { assertEquals(EXPECTED_STR_10, ODataExpressionParser.parseToJPAWhereExpression( getFilterExpressionMockedObj(ExpressionKind.PROPERTY, SALES_ORDER), TABLE_ALIAS)); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
@Test public void testAllBinaryOperators() { String parsedStr1 = ODataJPATestConstants.EMPTY_STRING; String parsedStr2 = ODataJPATestConstants.EMPTY_STRING; CommonExpression exp1 = getBinaryExpressionMockedObj(BinaryOperator.LT, ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_1); CommonExpression exp2 = getBinaryExpressionMockedObj(BinaryOperator.LE, ExpressionKind.PROPERTY, SALES_ABC, SAMPLE_DATA_XYZ); try { parsedStr1 = ODataExpressionParser.parseToJPAWhereExpression( (BinaryExpression) getBinaryExpression(exp1, BinaryOperator.AND, exp2), TABLE_ALIAS); assertEquals(EXPECTED_STR_4, parsedStr1); CommonExpression exp3 = getBinaryExpressionMockedObj(BinaryOperator.GT, ExpressionKind.PROPERTY, SAMPLE_DATA_LINE_ITEMS, SAMPLE_DATA_2); CommonExpression exp4 = getBinaryExpressionMockedObj(BinaryOperator.GE, ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_AMAZON); parsedStr2 = ODataExpressionParser.parseToJPAWhereExpression( getBinaryExpression(exp3, BinaryOperator.AND, exp4), TABLE_ALIAS); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } assertEquals(EXPECTED_STR_5, parsedStr2); }
@Test public void testParseMemberExpression() { try { assertEquals(EXPECTED_STR_6, ODataExpressionParser .parseToJPAWhereExpression( getBinaryExpression( getMemberExpressionMockedObj(ADDRESS, CITY), BinaryOperator.EQ, getLiteralExpressionMockedObj(SAMPLE_DATA_CITY_3)), TABLE_ALIAS)); assertEquals(EXPECTED_STR_7, ODataExpressionParser .parseToJPAWhereExpression( getBinaryExpression( getMultipleMemberExpressionMockedObj(ADDRESS, CITY, AREA), BinaryOperator.EQ, getLiteralExpressionMockedObj(SAMPLE_DATA_BTM)), TABLE_ALIAS)); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
@Test public void testParseMethodExpression() { try { assertEquals(EXPECTED_STR_12, ODataExpressionParser .parseToJPAWhereExpression( getBinaryExpression( getMethodExpressionMockedObj(MethodOperator.SUBSTRINGOF, "'Ru'", "currencyCode", null, 2), BinaryOperator.EQ, getLiteralExpressionMockedObj("true")), TABLE_ALIAS)); assertEquals(EXPECTED_STR_13, ODataExpressionParser .parseToJPAWhereExpression( getBinaryExpression( getMethodExpressionMockedObj(MethodOperator.SUBSTRING, "currencyCode", "1", "2", 3), BinaryOperator.EQ, getLiteralExpressionMockedObj("'NR'")), TABLE_ALIAS)); assertEquals(EXPECTED_STR_14, ODataExpressionParser .parseToJPAWhereExpression( getBinaryExpression( getMethodExpressionMockedObj(MethodOperator.TOLOWER, "currencyCode", null, null, 1), BinaryOperator.EQ, getLiteralExpressionMockedObj("'inr rupees'")), TABLE_ALIAS)); assertEquals(EXPECTED_STR_15, ODataExpressionParser .parseToJPAWhereExpression( getBinaryExpression( getMultipleMethodExpressionMockedObj(MethodOperator.SUBSTRINGOF, "'nr rupees'", MethodOperator.TOLOWER, "currencyCode", 2, 1), BinaryOperator.EQ, getLiteralExpressionMockedObj("true")), TABLE_ALIAS)); assertEquals(EXPECTED_STR_16, ODataExpressionParser .parseToJPAWhereExpression(getFilterExpressionForFunctionsMockedObj(MethodOperator.SUBSTRINGOF, "'INR'", null, "currencyCode", 2, null) , TABLE_ALIAS)); assertEquals(EXPECTED_STR_17, ODataExpressionParser .parseToJPAWhereExpression(getFilterExpressionForFunctionsMockedObj(MethodOperator.SUBSTRINGOF, "'nr rupees'", MethodOperator.TOLOWER, "currencyCode", 2, 1) , TABLE_ALIAS)); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
@Test public void testParseUnaryExpression() { UnaryExpression unaryExpression = getUnaryExpressionMockedObj( getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, "deliveryStatus"), com.sap.core.odata.api.uri.expression.UnaryOperator.NOT); try { assertEquals(EXPECTED_STR_11, ODataExpressionParser.parseToJPAWhereExpression( unaryExpression, TABLE_ALIAS)); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } } |
ODataExpressionParser { public static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias) throws ODataJPARuntimeException { String literal = null; String propertyName = null; EdmSimpleType edmSimpleType = null; StringBuilder keyFilters = new StringBuilder(); int i = 0; for (KeyPredicate keyPredicate : keyPredicates) { if (i > 0) { keyFilters.append(JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE); } i++; literal = keyPredicate.getLiteral(); try { EdmMapping mapping = keyPredicate.getProperty().getMapping(); if (mapping != null) { propertyName = keyPredicate.getProperty().getMapping().getInternalName(); } else { propertyName = keyPredicate.getProperty().getName(); } edmSimpleType = (EdmSimpleType) keyPredicate.getProperty().getType(); } catch (EdmException e) { throw ODataJPARuntimeException.throwException( ODataJPARuntimeException.GENERAL.addContent(e .getMessage()), e); } literal = evaluateComparingExpression(literal, edmSimpleType); if (edmSimpleType == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance() || edmSimpleType == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()) { literal = literal.substring(literal.indexOf('\''), literal.indexOf('}')); } keyFilters.append(tableAlias + JPQLStatement.DELIMITER.PERIOD + propertyName + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + literal); } if (keyFilters.length() > 0) { return keyFilters.toString(); } else { return null; } } static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias); static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields); static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression, final String tableAlias); static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias); static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(final List<EdmProperty> edmPropertylist, final String tableAlias); static final String EMPTY; static Integer methodFlag; } | @Test public void testParseKeyPredicates() { KeyPredicate keyPredicate1 = EasyMock.createMock(KeyPredicate.class); EdmProperty kpProperty1 = EasyMock.createMock(EdmProperty.class); EasyMock.expect(keyPredicate1.getLiteral()).andStubReturn("1"); KeyPredicate keyPredicate2 = EasyMock.createMock(KeyPredicate.class); EdmProperty kpProperty2 = EasyMock.createMock(EdmProperty.class); EasyMock.expect(keyPredicate2.getLiteral()).andStubReturn("abc"); EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class); try { EasyMock.expect(kpProperty1.getName()).andStubReturn(SAMPLE_DATA_FIELD1); EasyMock.expect(kpProperty1.getType()).andStubReturn( EdmSimpleTypeKind.Int32.getEdmSimpleTypeInstance()); EasyMock.expect(kpProperty2.getName()).andStubReturn(SAMPLE_DATA_FIELD2); EasyMock.expect(kpProperty2.getType()).andStubReturn( EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()); EasyMock.expect(keyPredicate1.getProperty()).andStubReturn(kpProperty1); EasyMock.expect(kpProperty1.getMapping()).andStubReturn(edmMapping); EasyMock.expect(edmMapping.getInternalName()).andReturn(SAMPLE_DATA_FIELD1); EasyMock.expect(keyPredicate2.getProperty()).andStubReturn(kpProperty2); EasyMock.expect(kpProperty2.getMapping()).andStubReturn(edmMapping); } catch (EdmException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } EasyMock.expect(edmMapping.getInternalName()).andReturn(SAMPLE_DATA_FIELD2); EasyMock.replay(edmMapping); EasyMock.replay(kpProperty1, keyPredicate1, kpProperty2, keyPredicate2); ArrayList<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>(); keyPredicates.add(keyPredicate1); keyPredicates.add(keyPredicate2); String str = null; try { str = ODataExpressionParser.parseKeyPredicates(keyPredicates, TABLE_ALIAS); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } assertEquals(EXPECTED_STR_8, str); } |
Team { public String getName() { return name; } Team(final int id, final String name); String getId(); String getName(); void setName(final String name); boolean isScrumTeam(); void setScrumTeam(final boolean isScrumTeam); List<Employee> getEmployees(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString(); } | @Test public void testName() { Team team1 = new Team(1, VALUE_NAME); assertEquals(team1.getName(), VALUE_NAME); } |
ODataExpressionParser { public static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields) { if ((selectedFields == null) || (selectedFields.size() == 0)) { return tableAlias; } String selectClause = EMPTY; Iterator<String> itr = selectedFields.iterator(); int count = 0; while (itr.hasNext()) { selectClause = selectClause + tableAlias + JPQLStatement.DELIMITER.PERIOD + itr.next(); count++; if (count < selectedFields.size()) { selectClause = selectClause + JPQLStatement.DELIMITER.COMMA + JPQLStatement.DELIMITER.SPACE; } } return selectClause; } static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias); static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields); static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression, final String tableAlias); static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias); static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(final List<EdmProperty> edmPropertylist, final String tableAlias); static final String EMPTY; static Integer methodFlag; } | @Test public void testParseToJPASelectExpression() { ArrayList<String> selectedFields = new ArrayList<String>(); selectedFields.add("BuyerAddress"); selectedFields.add("BuyerName"); selectedFields.add("BuyerId"); assertEquals(EXPECTED_STR_9, ODataExpressionParser.parseToJPASelectExpression(TABLE_ALIAS, selectedFields)); assertEquals(TABLE_ALIAS, ODataExpressionParser.parseToJPASelectExpression( TABLE_ALIAS, null)); selectedFields.clear(); assertEquals(TABLE_ALIAS, ODataExpressionParser.parseToJPASelectExpression( TABLE_ALIAS, selectedFields)); } |
JPAExpandCallBack implements OnWriteFeedContent, OnWriteEntryContent, ODataCallback { @Override public WriteEntryCallbackResult retrieveEntryResult( final WriteEntryCallbackContext context) { WriteEntryCallbackResult result = new WriteEntryCallbackResult(); Map<String, Object> entry = context.getEntryData(); Map<String, Object> edmPropertyValueMap = null; List<EdmNavigationProperty> currentNavPropertyList = null; Map<String, ExpandSelectTreeNode> navigationLinks = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); EdmNavigationProperty currentNavigationProperty = context.getNavigationProperty(); try { Object inlinedEntry = entry.get(currentNavigationProperty.getName()); if (nextEntitySet == null) { nextEntitySet = context.getSourceEntitySet().getRelatedEntitySet(currentNavigationProperty); } edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(inlinedEntry, nextEntitySet.getEntityType()); result.setEntryData(edmPropertyValueMap); navigationLinks = context.getCurrentExpandSelectTreeNode().getLinks(); if (navigationLinks.size() > 0) { currentNavPropertyList = new ArrayList<EdmNavigationProperty>(); currentNavPropertyList.add(getNextNavigationProperty(context.getSourceEntitySet().getEntityType(), context.getNavigationProperty())); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap(inlinedEntry, currentNavPropertyList); edmPropertyValueMap.putAll(navigationMap); result.setEntryData(edmPropertyValueMap); } result.setInlineProperties(getInlineEntityProviderProperties(context)); } catch (EdmException e) { } catch (ODataJPARuntimeException e) { } return result; } private JPAExpandCallBack(final URI baseUri, final List<ArrayList<NavigationPropertySegment>> expandList); @Override WriteEntryCallbackResult retrieveEntryResult(
final WriteEntryCallbackContext context); @Override WriteFeedCallbackResult retrieveFeedResult(
final WriteFeedCallbackContext context); static Map<String, ODataCallback> getCallbacks(final URI baseUri, final ExpandSelectTreeNode expandSelectTreeNode, final List<ArrayList<NavigationPropertySegment>> expandList); } | @Test public void testRetrieveEntryResult() { JPAExpandCallBack callBack = getJPAExpandCallBackObject(); WriteEntryCallbackContext writeFeedContext = EdmMockUtil.getWriteEntryCallBackContext(); try { Field field = callBack.getClass().getDeclaredField("nextEntitySet"); field.setAccessible(true); field.set(callBack, EdmMockUtil.mockTargetEntitySet()); WriteEntryCallbackResult result = callBack.retrieveEntryResult(writeFeedContext); assertEquals(1, result.getEntryData().size()); } catch (SecurityException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (NoSuchFieldException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (IllegalArgumentException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (IllegalAccessException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } } |
ODataExceptionWrapper { public ODataResponse wrapInExceptionResponse(final Exception exception) { try { final Exception toHandleException = extractException(exception); fillErrorContext(toHandleException); if (toHandleException instanceof ODataApplicationException) { enhanceContextWithApplicationException((ODataApplicationException) toHandleException); } else if (toHandleException instanceof ODataMessageException) { enhanceContextWithMessageException((ODataMessageException) toHandleException); } ODataResponse oDataResponse; if (callback != null) { oDataResponse = handleErrorCallback(callback); } else { oDataResponse = EntityProvider.writeErrorDocument(errorContext); } return oDataResponse; } catch (Exception e) { ODataResponse response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); return response; } } ODataExceptionWrapper(final ODataContext context, final Map<String, String> queryParameters, final List<String> acceptHeaderContentTypes); ODataExceptionWrapper(final UriInfo uriInfo, final HttpHeaders httpHeaders, final ServletConfig servletConfig, final HttpServletRequest servletRequest); ODataResponse wrapInExceptionResponse(final Exception exception); } | @Test public void testCallbackPathInfoAvailable() throws Exception { ODataContextImpl context = getMockedContext("http: ODataErrorCallback errorCallback = new ODataErrorCallback() { @Override public ODataResponse handleError(final ODataErrorContext context) throws ODataApplicationException { PathInfo pathInfo = context.getPathInfo(); assertEquals("ODataServiceRoot", pathInfo.getServiceRoot().toString()); assertEquals("http: return ODataResponse.entity("bla").status(HttpStatusCodes.BAD_REQUEST).contentHeader("text/html").build(); } }; when(context.getServiceFactory()).thenReturn(new MapperServiceFactory(errorCallback)); Map<String, String> queryParameters = Collections.emptyMap(); List<String> acceptContentTypes = Arrays.asList("text/html"); ODataExceptionWrapper exceptionWrapper = createWrapper(context, queryParameters, acceptContentTypes); ODataResponse response = exceptionWrapper.wrapInExceptionResponse(new Exception()); assertNotNull(response); assertEquals(HttpStatusCodes.BAD_REQUEST.getStatusCode(), response.getStatus().getStatusCode()); String errorMessage = (String) response.getEntity(); assertEquals("bla", errorMessage); String contentTypeHeader = response.getContentHeader(); assertEquals("text/html", contentTypeHeader); } |
BatchRequestParser { public List<BatchRequestPart> parse(final InputStream in) throws BatchException { Scanner scanner = new Scanner(in, BatchHelper.DEFAULT_ENCODING).useDelimiter(LF); baseUri = getBaseUri(); List<BatchRequestPart> requestList; try { requestList = parseBatchRequest(scanner); } finally { scanner.close(); try { in.close(); } catch (IOException e) { throw new ODataRuntimeException(e); } } return requestList; } BatchRequestParser(final String contentType, final EntityProviderBatchProperties properties); List<BatchRequestPart> parse(final InputStream in); } | @Test public void test() throws IOException, BatchException, URISyntaxException { String fileName = "/batchWithPost.txt"; InputStream in = ClassLoader.class.getResourceAsStream(fileName); if (in == null) { throw new IOException("Requested file '" + fileName + "' was not found."); } BatchRequestParser parser = new BatchRequestParser(contentType, batchProperties); List<BatchRequestPart> batchRequestParts = parser.parse(in); assertNotNull(batchRequestParts); assertEquals(false, batchRequestParts.isEmpty()); for (BatchRequestPart object : batchRequestParts) { if (!object.isChangeSet()) { assertEquals(1, object.getRequests().size()); ODataRequest retrieveRequest = object.getRequests().get(0); assertEquals(ODataHttpMethod.GET, retrieveRequest.getMethod()); if (!retrieveRequest.getAcceptableLanguages().isEmpty()) { assertEquals(3, retrieveRequest.getAcceptableLanguages().size()); } assertEquals(new URI(SERVICE_ROOT), retrieveRequest.getPathInfo().getServiceRoot()); ODataPathSegmentImpl pathSegment = new ODataPathSegmentImpl("Employees('2')", null); assertEquals(pathSegment.getPath(), retrieveRequest.getPathInfo().getODataSegments().get(0).getPath()); if (retrieveRequest.getQueryParameters().get("$format") != null) { assertEquals("json", retrieveRequest.getQueryParameters().get("$format")); } assertEquals(SERVICE_ROOT + "Employees('2')/EmployeeName?$format=json", retrieveRequest.getPathInfo().getRequestUri().toASCIIString()); } else { List<ODataRequest> requests = object.getRequests(); for (ODataRequest request : requests) { assertEquals(ODataHttpMethod.PUT, request.getMethod()); assertEquals("100000", request.getRequestHeaderValue(HttpHeaders.CONTENT_LENGTH.toLowerCase())); assertEquals("application/json;odata=verbose", request.getContentType()); assertEquals(3, request.getAcceptHeaders().size()); assertNotNull(request.getAcceptableLanguages()); assertTrue(request.getAcceptableLanguages().isEmpty()); assertEquals("*/*", request.getAcceptHeaders().get(2)); assertEquals("application/atomsvc+xml", request.getAcceptHeaders().get(0)); assertEquals(new URI(SERVICE_ROOT + "Employees('2')/EmployeeName").toASCIIString(), request.getPathInfo().getRequestUri().toASCIIString()); ODataPathSegmentImpl pathSegment = new ODataPathSegmentImpl("Employees('2')", null); assertEquals(pathSegment.getPath(), request.getPathInfo().getODataSegments().get(0).getPath()); ODataPathSegmentImpl pathSegment2 = new ODataPathSegmentImpl("EmployeeName", null); assertEquals(pathSegment2.getPath(), request.getPathInfo().getODataSegments().get(1).getPath()); } } } }
@Test public void testImageInContent() throws IOException, BatchException, URISyntaxException { String fileName = "/batchWithContent.txt"; InputStream contentInputStream = ClassLoader.class.getResourceAsStream(fileName); if (contentInputStream == null) { throw new IOException("Requested file '" + fileName + "' was not found."); } String content = StringHelper.inputStreamToString(contentInputStream); String batch = LF + "--batch_8194-cf13-1f56" + LF + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + LF + LF + "--changeset_f980-1cb6-94dd" + LF + "content-type: Application/http" + LF + "content-transfer-encoding: Binary" + LF + "Content-ID: 1" + LF + LF + "POST Employees HTTP/1.1" + LF + "Content-length: 100000" + LF + "Content-type: application/octet-stream" + LF + LF + content + LF + LF + "--changeset_f980-1cb6-94dd--" + LF + LF + "--batch_8194-cf13-1f56" + LF + MIME_HEADERS + LF + "GET Employees?$filter=Age%20gt%2040 HTTP/1.1" + LF + "Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1" + LF + "MaxDataServiceVersion: 2.0" + LF + LF + LF + "--batch_8194-cf13-1f56--"; List<BatchRequestPart> BatchRequestParts = parse(batch); for (BatchRequestPart object : BatchRequestParts) { if (!object.isChangeSet()) { assertEquals(1, object.getRequests().size()); ODataRequest retrieveRequest = object.getRequests().get(0); assertEquals(ODataHttpMethod.GET, retrieveRequest.getMethod()); assertEquals("Age gt 40", retrieveRequest.getQueryParameters().get("$filter")); assertEquals(new URI("http: } else { List<ODataRequest> requests = object.getRequests(); for (ODataRequest request : requests) { assertEquals(ODataHttpMethod.POST, request.getMethod()); assertEquals("100000", request.getRequestHeaderValue(HttpHeaders.CONTENT_LENGTH.toLowerCase())); assertEquals("1", request.getRequestHeaderValue(BatchHelper.MIME_HEADER_CONTENT_ID.toLowerCase())); assertEquals("application/octet-stream", request.getContentType()); InputStream body = request.getBody(); assertEquals(content, StringHelper.inputStreamToString(body)); } } } }
@Test public void testPostWithoutBody() throws IOException, BatchException, URISyntaxException { String fileName = "/batchWithContent.txt"; InputStream contentInputStream = ClassLoader.class.getResourceAsStream(fileName); if (contentInputStream == null) { throw new IOException("Requested file '" + fileName + "' was not found."); } StringHelper.inputStreamToString(contentInputStream); String batch = LF + "--batch_8194-cf13-1f56" + LF + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + LF + LF + "--changeset_f980-1cb6-94dd" + LF + MIME_HEADERS + LF + "POST Employees('2') HTTP/1.1" + LF + "Content-Length: 100" + LF + "Content-Type: application/octet-stream" + LF + LF + LF + "--changeset_f980-1cb6-94dd--" + LF + LF + "--batch_8194-cf13-1f56--"; List<BatchRequestPart> batchRequestParts = parse(batch); for (BatchRequestPart object : batchRequestParts) { if (object.isChangeSet()) { List<ODataRequest> requests = object.getRequests(); for (ODataRequest request : requests) { assertEquals(ODataHttpMethod.POST, request.getMethod()); assertEquals("100", request.getRequestHeaderValue(HttpHeaders.CONTENT_LENGTH.toLowerCase())); assertEquals("application/octet-stream", request.getContentType()); assertNotNull(request.getBody()); } } } }
@Test public void testBoundaryParameterWithQuotas() throws BatchException { String contentType = "multipart/mixed; boundary=\"batch_1.2+34:2j)0?\""; String batch = "--batch_1.2+34:2j)0?" + LF + GET_REQUEST + "--batch_1.2+34:2j)0?--"; InputStream in = new ByteArrayInputStream(batch.getBytes()); BatchRequestParser parser = new BatchRequestParser(contentType, batchProperties); List<BatchRequestPart> batchRequestParts = parser.parse(in); assertNotNull(batchRequestParts); assertEquals(false, batchRequestParts.isEmpty()); }
@Test(expected = BatchException.class) public void testBatchWithInvalidContentType() throws BatchException { String invalidContentType = "multipart;boundary=batch_1740-bb84-2f7f"; String batch = "--batch_1740-bb84-2f7f" + LF + GET_REQUEST + "--batch_1740-bb84-2f7f--"; InputStream in = new ByteArrayInputStream(batch.getBytes()); BatchRequestParser parser = new BatchRequestParser(invalidContentType, batchProperties); parser.parse(in); }
@Test(expected = BatchException.class) public void testBatchWithoutBoundaryParameter() throws BatchException { String invalidContentType = "multipart/mixed"; String batch = "--batch_1740-bb84-2f7f" + LF + GET_REQUEST + "--batch_1740-bb84-2f7f--"; InputStream in = new ByteArrayInputStream(batch.getBytes()); BatchRequestParser parser = new BatchRequestParser(invalidContentType, batchProperties); parser.parse(in); }
@Test(expected = BatchException.class) public void testBoundaryParameterWithoutQuota() throws BatchException { String invalidContentType = "multipart;boundary=batch_1740-bb:84-2f7f"; String batch = "--batch_1740-bb:84-2f7f" + LF + GET_REQUEST + "--batch_1740-bb:84-2f7f--"; InputStream in = new ByteArrayInputStream(batch.getBytes()); BatchRequestParser parser = new BatchRequestParser(invalidContentType, batchProperties); parser.parse(in); }
@Test public void testAcceptHeaders() throws BatchException, URISyntaxException { String batch = "--batch_8194-cf13-1f56" + LF + MIME_HEADERS + LF + "GET Employees('2')/EmployeeName HTTP/1.1" + LF + "Content-Length: 100000" + LF + "Content-Type: application/json;odata=verbose" + LF + "Accept: application/xml;q=0.3, application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, **", retrieveRequest.getAcceptHeaders().get(3)); } } }
@Test public void testAcceptHeaders2() throws BatchException, URISyntaxException { String batch = "--batch_8194-cf13-1f56" + LF + MIME_HEADERS + LF + "GET Employees('2')/EmployeeName HTTP/1.1" + LF + "Content-Length: 100000" + LF + "Content-Type: application/json;odata=verbose" + LF + "Accept: **", retrieveRequest.getAcceptHeaders().get(2)); } } }
@Test public void testAcceptHeaders3() throws BatchException, URISyntaxException { String batch = "--batch_8194-cf13-1f56" + LF + MIME_HEADERS + LF + "GET Employees('2')/EmployeeName HTTP/1.1" + LF + "Content-Length: 100000" + LF + "Content-Type: application/json;odata=verbose" + LF + "accept: */*,application/atom+xml,application/atomsvc+xml,application/xml" + LF + LF + LF + "--batch_8194-cf13-1f56--"; List<BatchRequestPart> batchRequestParts = parse(batch); for (BatchRequestPart multipart : batchRequestParts) { if (!multipart.isChangeSet()) { assertEquals(1, multipart.getRequests().size()); ODataRequest retrieveRequest = multipart.getRequests().get(0); assertEquals(ODataHttpMethod.GET, retrieveRequest.getMethod()); assertNotNull(retrieveRequest.getAcceptHeaders()); assertEquals(4, retrieveRequest.getAcceptHeaders().size()); assertEquals("application/atom+xml", retrieveRequest.getAcceptHeaders().get(0)); assertEquals("application/atomsvc+xml", retrieveRequest.getAcceptHeaders().get(1)); assertEquals("application/xml", retrieveRequest.getAcceptHeaders().get(2)); } } }
@Test public void testContentId() throws BatchException { String batch = "--batch_8194-cf13-1f56" + LF + MIME_HEADERS + LF + "GET Employees HTTP/1.1" + LF + "accept: */*,application/atom+xml,application/atomsvc+xml,application/xml" + LF + "Content-Id: BBB" + LF + LF + LF + "--batch_8194-cf13-1f56" + LF + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + LF + LF + "--changeset_f980-1cb6-94dd" + LF + MIME_HEADERS + "Content-Id: " + CONTENT_ID_REFERENCE + LF + LF + "POST Employees HTTP/1.1" + LF + "Content-type: application/octet-stream" + LF + LF + "/9j/4AAQSkZJRgABAQEBLAEsAAD/4RM0RXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAA" + LF + LF + "--changeset_f980-1cb6-94dd" + LF + MIME_HEADERS + "Content-ID: " + PUT_MIME_HEADER_CONTENT_ID + LF + LF + "PUT $" + CONTENT_ID_REFERENCE + "/EmployeeName HTTP/1.1" + LF + "Content-Type: application/json;odata=verbose" + LF + "Content-Id:" + PUT_REQUEST_HEADER_CONTENT_ID + LF + LF + "{\"EmployeeName\":\"Peter Fall\"}" + LF + "--changeset_f980-1cb6-94dd--" + LF + LF + "--batch_8194-cf13-1f56--"; InputStream in = new ByteArrayInputStream(batch.getBytes()); BatchRequestParser parser = new BatchRequestParser(contentType, batchProperties); List<BatchRequestPart> batchRequestParts = parser.parse(in); assertNotNull(batchRequestParts); for (BatchRequestPart multipart : batchRequestParts) { if (!multipart.isChangeSet()) { assertEquals(1, multipart.getRequests().size()); ODataRequest retrieveRequest = multipart.getRequests().get(0); assertEquals("BBB", retrieveRequest.getRequestHeaderValue(BatchHelper.REQUEST_HEADER_CONTENT_ID.toLowerCase())); } else { for (ODataRequest request : multipart.getRequests()) { if (ODataHttpMethod.POST.equals(request.getMethod())) { assertEquals(CONTENT_ID_REFERENCE, request.getRequestHeaderValue(BatchHelper.MIME_HEADER_CONTENT_ID.toLowerCase())); } else if (ODataHttpMethod.PUT.equals(request.getMethod())) { assertEquals(PUT_MIME_HEADER_CONTENT_ID, request.getRequestHeaderValue(BatchHelper.MIME_HEADER_CONTENT_ID.toLowerCase())); assertEquals(PUT_REQUEST_HEADER_CONTENT_ID, request.getRequestHeaderValue(BatchHelper.REQUEST_HEADER_CONTENT_ID.toLowerCase())); assertNull(request.getPathInfo().getRequestUri()); assertEquals("$" + CONTENT_ID_REFERENCE, request.getPathInfo().getODataSegments().get(0).getPath()); } } } } } |
JPAExpandCallBack implements OnWriteFeedContent, OnWriteEntryContent, ODataCallback { @Override public WriteFeedCallbackResult retrieveFeedResult( final WriteFeedCallbackContext context) { WriteFeedCallbackResult result = new WriteFeedCallbackResult(); HashMap<String, Object> inlinedEntry = (HashMap<String, Object>) context.getEntryData(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); List<EdmNavigationProperty> currentNavPropertyList = null; EdmNavigationProperty currentNavigationProperty = context.getNavigationProperty(); try { @SuppressWarnings({ "unchecked" }) List<Object> listOfItems = (List<Object>) inlinedEntry.get(context.getNavigationProperty().getName()); if (nextEntitySet == null) { nextEntitySet = context.getSourceEntitySet().getRelatedEntitySet(currentNavigationProperty); } for (Object object : listOfItems) { edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(object, nextEntitySet.getEntityType()); edmEntityList.add(edmPropertyValueMap); } result.setFeedData(edmEntityList); if (context.getCurrentExpandSelectTreeNode().getLinks().size() > 0) { currentNavPropertyList = new ArrayList<EdmNavigationProperty>(); currentNavPropertyList.add(getNextNavigationProperty(context.getSourceEntitySet().getEntityType(), context.getNavigationProperty())); int count = 0; for (Object object : listOfItems) { HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap(object, currentNavPropertyList); edmEntityList.get(count).putAll(navigationMap); count++; } result.setFeedData(edmEntityList); } result.setInlineProperties(getInlineEntityProviderProperties(context)); } catch (EdmException e) { } catch (ODataJPARuntimeException e) { } return result; } private JPAExpandCallBack(final URI baseUri, final List<ArrayList<NavigationPropertySegment>> expandList); @Override WriteEntryCallbackResult retrieveEntryResult(
final WriteEntryCallbackContext context); @Override WriteFeedCallbackResult retrieveFeedResult(
final WriteFeedCallbackContext context); static Map<String, ODataCallback> getCallbacks(final URI baseUri, final ExpandSelectTreeNode expandSelectTreeNode, final List<ArrayList<NavigationPropertySegment>> expandList); } | @Test public void testRetrieveFeedResult() { JPAExpandCallBack callBack = getJPAExpandCallBackObject(); WriteFeedCallbackContext writeFeedContext = EdmMockUtil.getWriteFeedCallBackContext(); try { Field field = callBack.getClass().getDeclaredField("nextEntitySet"); field.setAccessible(true); field.set(callBack, EdmMockUtil.mockTargetEntitySet()); WriteFeedCallbackResult result = callBack.retrieveFeedResult(writeFeedContext); assertEquals(2, result.getFeedData().size()); } catch (SecurityException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (NoSuchFieldException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (IllegalArgumentException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (IllegalAccessException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } } |
AcceptParser { public static List<String> parseAcceptHeaders(final String headerValue) throws BatchException { TreeSet<Accept> acceptTree = getAcceptTree(); List<String> acceptHeaders = new ArrayList<String>(); Scanner acceptHeaderScanner = new Scanner(headerValue).useDelimiter(",\\s?"); while (acceptHeaderScanner.hasNext()) { if (acceptHeaderScanner.hasNext(REG_EX_ACCEPT_WITH_Q_FACTOR)) { acceptHeaderScanner.next(REG_EX_ACCEPT_WITH_Q_FACTOR); MatchResult result = acceptHeaderScanner.match(); if (result.groupCount() == 2) { String acceptHeaderValue = result.group(1); double qualityFactor = result.group(2) != null ? Double.parseDouble(result.group(2)) : 1d; qualityFactor = getQualityFactor(acceptHeaderValue, qualityFactor); Accept acceptHeader = new Accept().setQuality(qualityFactor).setValue(acceptHeaderValue); acceptTree.add(acceptHeader); } else { String header = acceptHeaderScanner.next(); acceptHeaderScanner.close(); throw new BatchException(BatchException.INVALID_ACCEPT_HEADER.addContent(header), BAD_REQUEST); } } else { String header = acceptHeaderScanner.next(); acceptHeaderScanner.close(); throw new BatchException(BatchException.INVALID_ACCEPT_HEADER.addContent(header), BAD_REQUEST); } } for (Accept accept : acceptTree) { acceptHeaders.add(accept.getValue()); } acceptHeaderScanner.close(); return acceptHeaders; } static List<String> parseAcceptHeaders(final String headerValue); static List<String> parseAcceptableLanguages(final String headerValue); } | @Test public void testAcceptHeader() throws BatchException { List<String> acceptHeaders = AcceptParser.parseAcceptHeaders("text/html,application/xhtml+xml,application/xml;q=0.9,**", acceptHeaders.get(3)); }
@Test public void testAcceptHeaderWithParameter() throws BatchException { List<String> acceptHeaders = AcceptParser.parseAcceptHeaders("application/json;odata=verbose;q=1.0, **", acceptHeaders.get(1)); }
@Test public void testAcceptHeaderWithParameterAndLws() throws BatchException { List<String> acceptHeaders = AcceptParser.parseAcceptHeaders("application/json; odata=verbose;q=1.0, **", acceptHeaders.get(1)); }
@Test public void testAcceptHeaderWithTabulator() throws BatchException { List<String> acceptHeaders = AcceptParser.parseAcceptHeaders("application/json;\todata=verbose;q=1.0, **", acceptHeaders.get(1)); }
@Test public void testAcceptHeaderWithTwoParameters() throws BatchException { List<String> acceptHeaders = AcceptParser.parseAcceptHeaders("application/xml;another=test ; param=alskdf, **", acceptHeaders.get(1)); }
@Test public void testAcceptHeader2() throws BatchException { List<String> acceptHeaders = AcceptParser.parseAcceptHeaders("text/html;level=1, application*;q=0.1"); assertNotNull(acceptHeaders); assertEquals(3, acceptHeaders.size()); assertEquals("text/html;level=1", acceptHeaders.get(0)); assertEquals("application*", acceptHeaders.get(2)); }
@Test public void testMoreSpecificMediaType() throws BatchException { List<String> acceptHeaders = AcceptParser.parseAcceptHeaders("application/*, application/xml"); assertNotNull(acceptHeaders); assertEquals(2, acceptHeaders.size()); assertEquals("application/xml", acceptHeaders.get(0)); assertEquals("application/*", acceptHeaders.get(1)); }
@Test public void testQualityParameter() throws BatchException { List<String> acceptHeaders = AcceptParser.parseAcceptHeaders("application*; q=0.012"); assertNotNull(acceptHeaders); }
@Test(expected = BatchException.class) public void testInvalidAcceptHeader() throws BatchException { AcceptParser.parseAcceptHeaders("appi cation*;q=0.1"); }
@Test(expected = BatchException.class) public void testInvalidQualityParameter() throws BatchException { AcceptParser.parseAcceptHeaders("appication*;q=0,9"); }
@Test(expected = BatchException.class) public void testInvalidQualityParameter2() throws BatchException { AcceptParser.parseAcceptHeaders("appication*;q=1.0001"); } |
JPAExpandCallBack implements OnWriteFeedContent, OnWriteEntryContent, ODataCallback { public static <T> Map<String, ODataCallback> getCallbacks(final URI baseUri, final ExpandSelectTreeNode expandSelectTreeNode, final List<ArrayList<NavigationPropertySegment>> expandList) throws EdmException { Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>(); for (String navigationPropertyName : expandSelectTreeNode.getLinks().keySet()) { callbacks.put(navigationPropertyName, new JPAExpandCallBack(baseUri, expandList)); } return callbacks; } private JPAExpandCallBack(final URI baseUri, final List<ArrayList<NavigationPropertySegment>> expandList); @Override WriteEntryCallbackResult retrieveEntryResult(
final WriteEntryCallbackContext context); @Override WriteFeedCallbackResult retrieveFeedResult(
final WriteFeedCallbackContext context); static Map<String, ODataCallback> getCallbacks(final URI baseUri, final ExpandSelectTreeNode expandSelectTreeNode, final List<ArrayList<NavigationPropertySegment>> expandList); } | @Test public void testGetCallbacks() { Map<String, ODataCallback> callBacks = null; try { URI baseUri = new URI("http: ExpandSelectTreeNode expandSelectTreeNode = EdmMockUtil.mockExpandSelectTreeNode(); List<ArrayList<NavigationPropertySegment>> expandList = EdmMockUtil.getExpandList(); callBacks = JPAExpandCallBack.getCallbacks(baseUri, expandSelectTreeNode, expandList); } catch (URISyntaxException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (EdmException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } assertEquals(1, callBacks.size()); } |
AcceptParser { public static List<String> parseAcceptableLanguages(final String headerValue) throws BatchException { List<String> acceptLanguages = new LinkedList<String>(); TreeSet<Accept> acceptTree = getAcceptTree(); Scanner acceptLanguageScanner = new Scanner(headerValue).useDelimiter(",\\s?"); while (acceptLanguageScanner.hasNext()) { if (acceptLanguageScanner.hasNext(REG_EX_ACCEPT_LANGUAGES_WITH_Q_FACTOR)) { acceptLanguageScanner.next(REG_EX_ACCEPT_LANGUAGES_WITH_Q_FACTOR); MatchResult result = acceptLanguageScanner.match(); if (result.groupCount() == 2) { String languagerange = result.group(1); double qualityFactor = result.group(2) != null ? Double.parseDouble(result.group(2)) : 1d; acceptTree.add(new Accept().setQuality(qualityFactor).setValue(languagerange)); } else { String acceptLanguage = acceptLanguageScanner.next(); acceptLanguageScanner.close(); throw new BatchException(BatchException.INVALID_ACCEPT_LANGUAGE_HEADER.addContent(acceptLanguage), BAD_REQUEST); } } else { String acceptLanguage = acceptLanguageScanner.next(); acceptLanguageScanner.close(); throw new BatchException(BatchException.INVALID_ACCEPT_LANGUAGE_HEADER.addContent(acceptLanguage), BAD_REQUEST); } } for (Accept accept : acceptTree) { acceptLanguages.add(accept.getValue()); } acceptLanguageScanner.close(); return acceptLanguages; } static List<String> parseAcceptHeaders(final String headerValue); static List<String> parseAcceptableLanguages(final String headerValue); } | @Test public void testAcceptLanguages() throws BatchException { List<String> acceptLanguageHeaders = AcceptParser.parseAcceptableLanguages("en-US,en;q=0.7,en-UK;q=0.9"); assertNotNull(acceptLanguageHeaders); assertEquals(3, acceptLanguageHeaders.size()); assertEquals("en-US", acceptLanguageHeaders.get(0)); assertEquals("en-UK", acceptLanguageHeaders.get(1)); assertEquals("en", acceptLanguageHeaders.get(2)); }
@Test public void testAllAcceptLanguages() throws BatchException { List<String> acceptLanguageHeaders = AcceptParser.parseAcceptableLanguages("*"); assertNotNull(acceptLanguageHeaders); assertEquals(1, acceptLanguageHeaders.size()); }
@Test public void testLongAcceptLanguageValue() throws BatchException { List<String> acceptLanguageHeaders = AcceptParser.parseAcceptableLanguages("english"); assertNotNull(acceptLanguageHeaders); assertEquals("english", acceptLanguageHeaders.get(0)); }
@Test(expected = BatchException.class) public void testInvalidAcceptLanguageValue() throws BatchException { AcceptParser.parseAcceptableLanguages("en_US"); } |
JPAExpandCallBack implements OnWriteFeedContent, OnWriteEntryContent, ODataCallback { private EdmNavigationProperty getNextNavigationProperty( final EdmEntityType sourceEntityType, final EdmNavigationProperty navigationProperty) throws EdmException { int count; for (ArrayList<NavigationPropertySegment> navPropSegments : expandList) { count = 0; for (NavigationPropertySegment navPropSegment : navPropSegments) { EdmNavigationProperty navProperty = navPropSegment.getNavigationProperty(); if (navProperty.getFromRole().equalsIgnoreCase(sourceEntityType.getName()) && navProperty.getName().equals(navigationProperty.getName())) { return navPropSegments.get(count + 1).getNavigationProperty(); } else { count++; } } } return null; } private JPAExpandCallBack(final URI baseUri, final List<ArrayList<NavigationPropertySegment>> expandList); @Override WriteEntryCallbackResult retrieveEntryResult(
final WriteEntryCallbackContext context); @Override WriteFeedCallbackResult retrieveFeedResult(
final WriteFeedCallbackContext context); static Map<String, ODataCallback> getCallbacks(final URI baseUri, final ExpandSelectTreeNode expandSelectTreeNode, final List<ArrayList<NavigationPropertySegment>> expandList); } | @Test public void testGetNextNavigationProperty() { JPAExpandCallBack callBack = getJPAExpandCallBackObject(); List<ArrayList<NavigationPropertySegment>> expandList = EdmMockUtil.getExpandList(); ArrayList<NavigationPropertySegment> expands = expandList.get(0); expands.add(EdmMockUtil.mockThirdNavigationPropertySegment()); EdmNavigationProperty result = null; try { Field field = callBack.getClass().getDeclaredField("expandList"); field.setAccessible(true); field.set(callBack, expandList); Class<?>[] formalParams = { EdmEntityType.class, EdmNavigationProperty.class }; Object[] actualParams = { EdmMockUtil.mockSourceEdmEntityType(), EdmMockUtil.mockNavigationProperty() }; Method method = callBack.getClass().getDeclaredMethod("getNextNavigationProperty", formalParams); method.setAccessible(true); result = (EdmNavigationProperty) method.invoke(callBack, actualParams); assertEquals("MaterialDetails", result.getName()); } catch (SecurityException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (NoSuchFieldException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (IllegalArgumentException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (IllegalAccessException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (NoSuchMethodException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (InvocationTargetException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (EdmException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } } |
BatchResponseParser { public List<BatchSingleResponse> parse(final InputStream in) throws BatchException { Scanner scanner = new Scanner(in, BatchHelper.DEFAULT_ENCODING).useDelimiter(LF); List<BatchSingleResponse> responseList; try { responseList = Collections.unmodifiableList(parseBatchResponse(scanner)); } finally { scanner.close(); try { in.close(); } catch (IOException e) { throw new ODataRuntimeException(e); } } return responseList; } BatchResponseParser(final String contentType); List<BatchSingleResponse> parse(final InputStream in); } | @Test public void testSimpleBatchResponse() throws BatchException { String getResponse = "--batch_123" + LF + "Content-Type: application/http" + LF + "Content-Transfer-Encoding: binary" + LF + "Content-ID: 1" + LF + LF + "HTTP/1.1 200 OK" + LF + "DataServiceVersion: 2.0" + LF + "Content-Type: text/plain;charset=utf-8" + LF + "Content-length: 22" + LF + LF + "Frederic Fall MODIFIED" + LF + LF + "--batch_123--"; InputStream in = new ByteArrayInputStream(getResponse.getBytes()); BatchResponseParser parser = new BatchResponseParser("multipart/mixed;boundary=batch_123"); List<BatchSingleResponse> responses = parser.parse(in); for (BatchSingleResponse response : responses) { assertEquals("200", response.getStatusCode()); assertEquals("OK", response.getStatusInfo()); assertEquals("text/plain;charset=utf-8", response.getHeaders().get(HttpHeaders.CONTENT_TYPE)); assertEquals("22", response.getHeaders().get("Content-length")); assertEquals("1", response.getContentId()); } }
@Test public void testBatchResponse() throws BatchException, IOException { String fileName = "/batchResponse.txt"; InputStream in = ClassLoader.class.getResourceAsStream(fileName); if (in == null) { throw new IOException("Requested file '" + fileName + "' was not found."); } BatchResponseParser parser = new BatchResponseParser("multipart/mixed;boundary=batch_123"); List<BatchSingleResponse> responses = parser.parse(in); for (BatchSingleResponse response : responses) { if ("1".equals(response.getContentId())) { assertEquals("204", response.getStatusCode()); assertEquals("No Content", response.getStatusInfo()); } else if ("3".equals(response.getContentId())) { assertEquals("200", response.getStatusCode()); assertEquals("OK", response.getStatusInfo()); } } }
@Test public void testResponseToChangeSet() throws BatchException { String putResponse = "--batch_123" + LF + "Content-Type: " + HttpContentType.MULTIPART_MIXED + ";boundary=changeset_12ks93js84d" + LF + LF + "--changeset_12ks93js84d" + LF + "Content-Type: application/http" + LF + "Content-Transfer-Encoding: binary" + LF + "Content-ID: 1" + LF + LF + "HTTP/1.1 204 No Content" + LF + "DataServiceVersion: 2.0" + LF + LF + LF + "--changeset_12ks93js84d--" + LF + LF + "--batch_123--"; InputStream in = new ByteArrayInputStream(putResponse.getBytes()); BatchResponseParser parser = new BatchResponseParser("multipart/mixed;boundary=batch_123"); List<BatchSingleResponse> responses = parser.parse(in); for (BatchSingleResponse response : responses) { assertEquals("204", response.getStatusCode()); assertEquals("No Content", response.getStatusInfo()); assertEquals("1", response.getContentId()); } } |
BatchRequestWriter { public InputStream writeBatchRequest(final List<BatchPart> batchParts, final String boundary) { if (boundary.matches(REG_EX_BOUNDARY)) { batchBoundary = boundary; } else { throw new IllegalArgumentException(); } for (BatchPart batchPart : batchParts) { writer.append("--" + boundary).append(LF); if (batchPart instanceof BatchChangeSet) { appendChangeSet((BatchChangeSet) batchPart); } else if (batchPart instanceof BatchQueryPart) { BatchQueryPart request = (BatchQueryPart) batchPart; appendRequestBodyPart(request.getMethod(), request.getUri(), null, request.getHeaders(), request.getContentId()); } } writer.append("--").append(boundary).append("--").append(LF).append(LF); InputStream batchRequestBody; batchRequestBody = new ByteArrayInputStream(BatchHelper.getBytes(writer.toString())); return batchRequestBody; } InputStream writeBatchRequest(final List<BatchPart> batchParts, final String boundary); } | @Test public void testBatchQueryPart() throws BatchException, IOException { List<BatchPart> batch = new ArrayList<BatchPart>(); Map<String, String> headers = new HashMap<String, String>(); headers.put("Accept", "application/json"); BatchPart request = BatchQueryPart.method(GET).uri("Employees").headers(headers).build(); batch.add(request); BatchRequestWriter writer = new BatchRequestWriter(); InputStream batchRequest = writer.writeBatchRequest(batch, BOUNDARY); String requestBody = StringHelper.inputStreamToString(batchRequest); assertNotNull(batchRequest); checkMimeHeaders(requestBody); assertTrue(requestBody.contains("--batch_")); assertTrue(requestBody.contains("GET Employees HTTP/1.1")); checkHeaders(headers, requestBody); }
@Test public void testBatchChangeSet() throws IOException, BatchException { List<BatchPart> batch = new ArrayList<BatchPart>(); Map<String, String> headers = new HashMap<String, String>(); headers.put("content-type", "application/json"); BatchChangeSetPart request = BatchChangeSetPart.method(PUT) .uri("Employees('2')") .body("{\"Возраст\":40}") .headers(headers) .contentId("111") .build(); BatchChangeSet changeSet = BatchChangeSet.newBuilder().build(); changeSet.add(request); batch.add(changeSet); BatchRequestWriter writer = new BatchRequestWriter(); InputStream batchRequest = writer.writeBatchRequest(batch, BOUNDARY); String requestBody = StringHelper.inputStreamToString(batchRequest, true); assertNotNull(batchRequest); checkMimeHeaders(requestBody); checkHeaders(headers, requestBody); assertTrue(requestBody.contains("--batch_")); assertTrue(requestBody.contains("--changeset_")); assertTrue(requestBody.contains("PUT Employees('2') HTTP/1.1")); assertTrue(requestBody.contains("{\"Возраст\":40}")); }
@Test public void testBatchWithGetAndPost() throws BatchException, IOException { List<BatchPart> batch = new ArrayList<BatchPart>(); Map<String, String> headers = new HashMap<String, String>(); headers.put("Accept", "application/json"); BatchPart request = BatchQueryPart.method(GET).uri("Employees").headers(headers).contentId("000").build(); batch.add(request); Map<String, String> changeSetHeaders = new HashMap<String, String>(); changeSetHeaders.put("content-type", "application/json"); String body = "/9j/4AAQSkZJRgABAQEBLAEsAAD/4RM0RXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEA"; BatchChangeSetPart changeRequest = BatchChangeSetPart.method(POST) .uri("Employees") .body(body) .headers(changeSetHeaders) .contentId("111") .build(); BatchChangeSet changeSet = BatchChangeSet.newBuilder().build(); changeSet.add(changeRequest); batch.add(changeSet); BatchRequestWriter writer = new BatchRequestWriter(); InputStream batchRequest = writer.writeBatchRequest(batch, BOUNDARY); String requestBody = StringHelper.inputStreamToString(batchRequest); assertNotNull(batchRequest); checkMimeHeaders(requestBody); checkHeaders(headers, requestBody); checkHeaders(changeSetHeaders, requestBody); assertTrue(requestBody.contains("GET Employees HTTP/1.1")); assertTrue(requestBody.contains("POST Employees HTTP/1.1")); assertTrue(requestBody.contains(body)); }
@Test public void testChangeSetWithContentIdReferencing() throws BatchException, IOException { List<BatchPart> batch = new ArrayList<BatchPart>(); Map<String, String> changeSetHeaders = new HashMap<String, String>(); changeSetHeaders.put("content-type", "application/json"); String body = "/9j/4AAQSkZJRgABAQEBLAEsAAD/4RM0RXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEA"; BatchChangeSetPart changeRequest = BatchChangeSetPart.method(POST) .uri("Employees('2')") .body(body) .headers(changeSetHeaders) .contentId("1") .build(); BatchChangeSet changeSet = BatchChangeSet.newBuilder().build(); changeSet.add(changeRequest); changeSetHeaders = new HashMap<String, String>(); changeSetHeaders.put("content-type", "application/json;odata=verbose"); BatchChangeSetPart changeRequest2 = BatchChangeSetPart.method(PUT) .uri("$/ManagerId") .body("{\"ManagerId\":1}") .headers(changeSetHeaders) .contentId("2") .build(); changeSet.add(changeRequest2); batch.add(changeSet); BatchRequestWriter writer = new BatchRequestWriter(); InputStream batchRequest = writer.writeBatchRequest(batch, BOUNDARY); String requestBody = StringHelper.inputStreamToString(batchRequest); assertNotNull(batchRequest); checkMimeHeaders(requestBody); assertTrue(requestBody.contains("POST Employees('2') HTTP/1.1")); assertTrue(requestBody.contains("PUT $/ManagerId HTTP/1.1")); assertTrue(requestBody.contains(BatchHelper.HTTP_CONTENT_ID + ": 1")); assertTrue(requestBody.contains(BatchHelper.HTTP_CONTENT_ID + ": 2")); assertTrue(requestBody.contains(body)); }
@Test public void testBatchWithTwoChangeSets() throws BatchException, IOException { List<BatchPart> batch = new ArrayList<BatchPart>(); Map<String, String> changeSetHeaders = new HashMap<String, String>(); changeSetHeaders.put("content-type", "application/json"); changeSetHeaders.put("content-Id", "111"); String body = "/9j/4AAQSkZJRgABAQEBLAEsAAD/4RM0RXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEA"; BatchChangeSetPart changeRequest = BatchChangeSetPart.method(POST) .uri("Employees") .body(body) .headers(changeSetHeaders) .build(); BatchChangeSet changeSet = BatchChangeSet.newBuilder().build(); changeSet.add(changeRequest); batch.add(changeSet); Map<String, String> changeSetHeaders2 = new HashMap<String, String>(); changeSetHeaders2.put("content-type", "application/json;odata=verbose"); changeSetHeaders2.put("content-Id", "222"); BatchChangeSetPart changeRequest2 = BatchChangeSetPart.method(PUT) .uri("Employees('2')/ManagerId") .body("{\"ManagerId\":1}") .headers(changeSetHeaders2) .build(); BatchChangeSet changeSet2 = BatchChangeSet.newBuilder().build(); changeSet2.add(changeRequest2); batch.add(changeSet2); BatchRequestWriter writer = new BatchRequestWriter(); InputStream batchRequest = writer.writeBatchRequest(batch, BOUNDARY); String requestBody = StringHelper.inputStreamToString(batchRequest); assertNotNull(batchRequest); checkMimeHeaders(requestBody); assertTrue(requestBody.contains("POST Employees HTTP/1.1")); assertTrue(requestBody.contains("PUT Employees('2')/ManagerId HTTP/1.1")); assertTrue(requestBody.contains(body)); } |
BatchResponseWriter { public ODataResponse writeResponse(final List<BatchResponsePart> batchResponseParts) throws BatchException { String boundary = BatchHelper.generateBoundary("batch"); appendResponsePart(batchResponseParts, boundary); String batchResponseBody = writer.toString(); return ODataResponse.entity(batchResponseBody).status(HttpStatusCodes.ACCEPTED) .header(HttpHeaders.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED + "; boundary=" + boundary) .header(HttpHeaders.CONTENT_LENGTH, String.valueOf(writer.length())) .build(); } ODataResponse writeResponse(final List<BatchResponsePart> batchResponseParts); } | @Test public void testBatchResponse() throws BatchException, IOException { List<BatchResponsePart> parts = new ArrayList<BatchResponsePart>(); ODataResponse response = ODataResponse.entity("Walter Winter") .status(HttpStatusCodes.OK) .contentHeader("application/json") .build(); List<ODataResponse> responses = new ArrayList<ODataResponse>(1); responses.add(response); parts.add(BatchResponsePart.responses(responses).changeSet(false).build()); ODataResponse changeSetResponse = ODataResponse.status(HttpStatusCodes.NO_CONTENT).build(); responses = new ArrayList<ODataResponse>(1); responses.add(changeSetResponse); parts.add(BatchResponsePart.responses(responses).changeSet(true).build()); BatchResponseWriter writer = new BatchResponseWriter(); ODataResponse batchResponse = writer.writeResponse(parts); assertEquals(202, batchResponse.getStatus().getStatusCode()); assertNotNull(batchResponse.getEntity()); String body = (String) batchResponse.getEntity(); assertTrue(body.contains("--batch")); assertTrue(body.contains("--changeset")); assertTrue(body.contains("HTTP/1.1 200 OK")); assertTrue(body.contains("Content-Type: application/http")); assertTrue(body.contains("Content-Transfer-Encoding: binary")); assertTrue(body.contains("Walter Winter")); assertTrue(body.contains("multipart/mixed; boundary=changeset")); assertTrue(body.contains("HTTP/1.1 204 No Content")); }
@Test public void testResponse() throws BatchException, IOException { List<BatchResponsePart> parts = new ArrayList<BatchResponsePart>(); ODataResponse response = ODataResponse.entity("Walter Winter").status(HttpStatusCodes.OK).contentHeader("application/json").build(); List<ODataResponse> responses = new ArrayList<ODataResponse>(1); responses.add(response); parts.add(BatchResponsePart.responses(responses).changeSet(false).build()); BatchResponseWriter writer = new BatchResponseWriter(); ODataResponse batchResponse = writer.writeResponse(parts); assertEquals(202, batchResponse.getStatus().getStatusCode()); assertNotNull(batchResponse.getEntity()); String body = (String) batchResponse.getEntity(); assertTrue(body.contains("--batch")); assertFalse(body.contains("--changeset")); assertTrue(body.contains("HTTP/1.1 200 OK" + "\r\n")); assertTrue(body.contains("Content-Type: application/http" + "\r\n")); assertTrue(body.contains("Content-Transfer-Encoding: binary" + "\r\n")); assertTrue(body.contains("Walter Winter")); assertFalse(body.contains("multipart/mixed; boundary=changeset")); }
@Test public void testChangeSetResponse() throws BatchException, IOException { List<BatchResponsePart> parts = new ArrayList<BatchResponsePart>(); ODataResponse changeSetResponse = ODataResponse.status(HttpStatusCodes.NO_CONTENT).build(); List<ODataResponse> responses = new ArrayList<ODataResponse>(1); responses.add(changeSetResponse); parts.add(BatchResponsePart.responses(responses).changeSet(true).build()); BatchResponseWriter writer = new BatchResponseWriter(); ODataResponse batchResponse = writer.writeResponse(parts); assertEquals(202, batchResponse.getStatus().getStatusCode()); assertNotNull(batchResponse.getEntity()); String body = (String) batchResponse.getEntity(); assertTrue(body.contains("--batch")); assertTrue(body.contains("--changeset")); assertTrue(body.indexOf("--changeset") != body.lastIndexOf("--changeset")); assertFalse(body.contains("HTTP/1.1 200 OK" + "\r\n")); assertTrue(body.contains("Content-Type: application/http" + "\r\n")); assertTrue(body.contains("Content-Transfer-Encoding: binary" + "\r\n")); assertTrue(body.contains("HTTP/1.1 204 No Content" + "\r\n")); assertTrue(body.contains("Content-Type: multipart/mixed; boundary=changeset")); }
@Test public void testContentIdEchoing() throws BatchException, IOException { List<BatchResponsePart> parts = new ArrayList<BatchResponsePart>(); ODataResponse response = ODataResponse.entity("Walter Winter") .status(HttpStatusCodes.OK) .contentHeader("application/json") .header(BatchHelper.MIME_HEADER_CONTENT_ID, "mimeHeaderContentId123") .header(BatchHelper.REQUEST_HEADER_CONTENT_ID, "requestHeaderContentId123") .build(); List<ODataResponse> responses = new ArrayList<ODataResponse>(1); responses.add(response); parts.add(BatchResponsePart.responses(responses).changeSet(false).build()); BatchResponseWriter writer = new BatchResponseWriter(); ODataResponse batchResponse = writer.writeResponse(parts); assertEquals(202, batchResponse.getStatus().getStatusCode()); assertNotNull(batchResponse.getEntity()); String body = (String) batchResponse.getEntity(); String mimeHeader = "Content-Type: application/http" + "\r\n" + "Content-Transfer-Encoding: binary" + "\r\n" + "Content-Id: mimeHeaderContentId123" + "\r\n"; String requestHeader = "Content-Id: requestHeaderContentId123" + "\r\n" + "Content-Type: application/json" + "\r\n" + "Content-Length: 13" + "\r\n"; assertTrue(body.contains(mimeHeader)); assertTrue(body.contains(requestHeader)); } |
JPAEdmNameBuilder { public static FullQualifiedName build(final JPAEdmBaseView view, final String name) { FullQualifiedName fqName = new FullQualifiedName(buildNamespace(view), name); return fqName; } static FullQualifiedName build(final JPAEdmBaseView view, final String name); static void build(final JPAEdmEntityTypeView view); static void build(final JPAEdmSchemaView view); static void build(final JPAEdmPropertyView view, final boolean isComplexMode); static void build(final JPAEdmEntityContainerView view); static void build(final JPAEdmEntitySetView view,
final JPAEdmEntityTypeView entityTypeView); static void build(final JPAEdmComplexType view); static void build(final JPAEdmComplexPropertyView complexView,
final JPAEdmPropertyView propertyView); static void build(final JPAEdmComplexPropertyView complexView, final String parentComplexTypeName); static void build(final JPAEdmAssociationEndView assocaitionEndView,
final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView); static void build(final JPAEdmAssociationView view, final int count); static void build(final JPAEdmAssociationSetView view); static void build(final JPAEdmAssociationView associationView,
final JPAEdmPropertyView propertyView,
final JPAEdmNavigationPropertyView navPropertyView, final int count); } | @SuppressWarnings("rawtypes") @Test public void testBuildJPAEdmComplexPropertyViewJPAEdmPropertyView() { JPAEdmComplexPropertyView complexPropertyView = EasyMock.createMock(JPAEdmComplexPropertyView.class); ComplexProperty complexProperty = new ComplexProperty(); EasyMock.expect(complexPropertyView.getEdmComplexProperty()).andStubReturn(complexProperty); ODataJPAContextImpl oDataJPAContext = new ODataJPAContextImpl(); JPAEdmMappingModelService mappingModelService = new JPAEdmMappingModelService(oDataJPAContext); EasyMock.expect(complexPropertyView.getJPAEdmMappingModelAccess()).andStubReturn(mappingModelService); JPAEdmPropertyView propertyView = EasyMock.createMock(JPAEdmPropertyView.class); JPAEdmEntityTypeView entityTypeView = EasyMock.createMock(JPAEdmEntityTypeView.class); EasyMock.expect(entityTypeView.getJPAEntityType()).andStubReturn(new JEntityType()); EasyMock.replay(entityTypeView); EasyMock.expect(propertyView.getJPAAttribute()).andStubReturn(new JAttribute()); EasyMock.expect(propertyView.getJPAEdmEntityTypeView()).andStubReturn(entityTypeView); EasyMock.replay(complexPropertyView); EasyMock.replay(propertyView); JPAEdmNameBuilder.build(complexPropertyView, propertyView); assertEquals("Id", complexPropertyView.getEdmComplexProperty().getName()); } |
EdmAnnotationsImplProv implements EdmAnnotations { @Override public List<? extends EdmAnnotationAttribute> getAnnotationAttributes() { return annotationAttributes; } EdmAnnotationsImplProv(final List<AnnotationAttribute> annotationAttributes, final List<AnnotationElement> annotationElements); @Override List<? extends EdmAnnotationElement> getAnnotationElements(); @Override EdmAnnotationElement getAnnotationElement(final String name, final String namespace); @Override List<? extends EdmAnnotationAttribute> getAnnotationAttributes(); @Override EdmAnnotationAttribute getAnnotationAttribute(final String name, final String namespace); } | @Test public void testAttributes() { List<? extends EdmAnnotationAttribute> annotations = annotationsProvider.getAnnotationAttributes(); assertEquals(1, annotations.size()); Iterator<? extends EdmAnnotationAttribute> iterator = annotations.iterator(); while (iterator.hasNext()) { EdmAnnotationAttribute attribute = iterator.next(); assertEquals("attributeName", attribute.getName()); assertEquals("namespace", attribute.getNamespace()); assertEquals("prefix", attribute.getPrefix()); assertEquals("Text", attribute.getText()); } } |
EdmAnnotationsImplProv implements EdmAnnotations { @Override public EdmAnnotationAttribute getAnnotationAttribute(final String name, final String namespace) { if (annotationElements != null) { Iterator<? extends EdmAnnotationAttribute> annotationAttributesIterator = annotationAttributes.iterator(); while (annotationAttributesIterator.hasNext()) { EdmAnnotationAttribute annotationAttribute = annotationAttributesIterator.next(); if (annotationAttribute.getName().equals(name) && annotationAttribute.getNamespace().equals(namespace)) { return annotationAttribute; } } } return null; } EdmAnnotationsImplProv(final List<AnnotationAttribute> annotationAttributes, final List<AnnotationElement> annotationElements); @Override List<? extends EdmAnnotationElement> getAnnotationElements(); @Override EdmAnnotationElement getAnnotationElement(final String name, final String namespace); @Override List<? extends EdmAnnotationAttribute> getAnnotationAttributes(); @Override EdmAnnotationAttribute getAnnotationAttribute(final String name, final String namespace); } | @Test public void testAttribute() { EdmAnnotationAttribute attribute = annotationsProvider.getAnnotationAttribute("attributeName", "namespace"); assertEquals("attributeName", attribute.getName()); assertEquals("namespace", attribute.getNamespace()); assertEquals("prefix", attribute.getPrefix()); assertEquals("Text", attribute.getText()); }
@Test public void testAttributeNull() { EdmAnnotationAttribute attribute = annotationsProvider.getAnnotationAttribute("attributeNameWrong", "namespaceWrong"); assertNull(attribute); } |
EdmAnnotationsImplProv implements EdmAnnotations { @Override public List<? extends EdmAnnotationElement> getAnnotationElements() { return annotationElements; } EdmAnnotationsImplProv(final List<AnnotationAttribute> annotationAttributes, final List<AnnotationElement> annotationElements); @Override List<? extends EdmAnnotationElement> getAnnotationElements(); @Override EdmAnnotationElement getAnnotationElement(final String name, final String namespace); @Override List<? extends EdmAnnotationAttribute> getAnnotationAttributes(); @Override EdmAnnotationAttribute getAnnotationAttribute(final String name, final String namespace); } | @Test public void testElements() { List<? extends EdmAnnotationElement> annotations = annotationsProvider.getAnnotationElements(); assertEquals(1, annotations.size()); Iterator<? extends EdmAnnotationElement> iterator = annotations.iterator(); while (iterator.hasNext()) { EdmAnnotationElement element = iterator.next(); assertEquals("elementName", element.getName()); assertEquals("namespace", element.getNamespace()); assertEquals("prefix", element.getPrefix()); assertEquals("xmlData", element.getText()); } } |
EdmAnnotationsImplProv implements EdmAnnotations { @Override public EdmAnnotationElement getAnnotationElement(final String name, final String namespace) { if (annotationElements != null) { Iterator<? extends EdmAnnotationElement> annotationElementIterator = annotationElements.iterator(); while (annotationElementIterator.hasNext()) { EdmAnnotationElement annotationElement = annotationElementIterator.next(); if (annotationElement.getName().equals(name) && annotationElement.getNamespace().equals(namespace)) { return annotationElement; } } } return null; } EdmAnnotationsImplProv(final List<AnnotationAttribute> annotationAttributes, final List<AnnotationElement> annotationElements); @Override List<? extends EdmAnnotationElement> getAnnotationElements(); @Override EdmAnnotationElement getAnnotationElement(final String name, final String namespace); @Override List<? extends EdmAnnotationAttribute> getAnnotationAttributes(); @Override EdmAnnotationAttribute getAnnotationAttribute(final String name, final String namespace); } | @Test public void testElement() { EdmAnnotationElement element = annotationsProvider.getAnnotationElement("elementName", "namespace"); assertEquals("elementName", element.getName()); assertEquals("namespace", element.getNamespace()); assertEquals("prefix", element.getPrefix()); assertEquals("xmlData", element.getText()); }
@Test public void testElementNull() { EdmAnnotationElement element = annotationsProvider.getAnnotationElement("elementNameWrong", "namespaceWrong"); assertNull(element); } |
EdmPropertyImplProv extends EdmElementImplProv implements EdmProperty, EdmAnnotatable { @Override public EdmAnnotations getAnnotations() throws EdmException { return new EdmAnnotationsImplProv(property.getAnnotationAttributes(), property.getAnnotationElements()); } EdmPropertyImplProv(final EdmImplProv edm, final FullQualifiedName propertyName, final Property property); @Override EdmCustomizableFeedMappings getCustomizableFeedMappings(); @Override String getMimeType(); @Override EdmAnnotations getAnnotations(); } | @Test public void getAnnotations() throws Exception { EdmAnnotatable annotatable = propertySimpleProvider; EdmAnnotations annotations = annotatable.getAnnotations(); assertNull(annotations.getAnnotationAttributes()); assertNull(annotations.getAnnotationElements()); } |
JPATypeConvertor { public static EdmSimpleTypeKind convertToEdmSimpleType(final Class<?> jpaType, final Attribute<?, ?> currentAttribute) throws ODataJPAModelException { if (jpaType.equals(String.class)) { return EdmSimpleTypeKind.String; } else if (jpaType.equals(Long.class) || jpaType.equals(long.class)) { return EdmSimpleTypeKind.Int64; } else if (jpaType.equals(Short.class) || jpaType.equals(short.class)) { return EdmSimpleTypeKind.Int16; } else if (jpaType.equals(Integer.class) || jpaType.equals(int.class)) { return EdmSimpleTypeKind.Int32; } else if (jpaType.equals(Double.class) || jpaType.equals(double.class)) { return EdmSimpleTypeKind.Double; } else if (jpaType.equals(Float.class) || jpaType.equals(float.class)) { return EdmSimpleTypeKind.Single; } else if (jpaType.equals(BigDecimal.class)) { return EdmSimpleTypeKind.Decimal; } else if (jpaType.equals(byte[].class)) { return EdmSimpleTypeKind.Binary; } else if (jpaType.equals(Byte.class) || jpaType.equals(byte.class)) { return EdmSimpleTypeKind.SByte; } else if (jpaType.equals(Byte[].class)) { return EdmSimpleTypeKind.Binary; } else if (jpaType.equals(Boolean.class) || jpaType.equals(boolean.class)) { return EdmSimpleTypeKind.Boolean; } else if ((jpaType.equals(Date.class)) || (jpaType.equals(Calendar.class))) { return dateConversion(currentAttribute, false); } else if (jpaType.equals(UUID.class)) { return EdmSimpleTypeKind.Guid; } else if (jpaType.equals(java.sql.Date.class) || jpaType.equals(java.sql.Time.class) || jpaType.equals(java.sql.Timestamp.class)) { return dateConversion(currentAttribute, true); } throw ODataJPAModelException.throwException(ODataJPAModelException.TYPE_NOT_SUPPORTED.addContent(jpaType.toString()), null); } static EdmSimpleTypeKind convertToEdmSimpleType(final Class<?> jpaType, final Attribute<?, ?> currentAttribute); } | @Test public void testConvertToEdmSimpleType() { String str = "entity"; byte[] byteArr = new byte[3]; Long longObj = new Long(0); Short shortObj = new Short((short) 0); Integer integerObj = new Integer(0); Double doubleObj = new Double(0); Float floatObj = new Float(0); BigDecimal bigDecimalObj = new BigDecimal(0); Byte byteObj = new Byte((byte) 0); Boolean booleanObj = Boolean.TRUE; UUID uUID = new UUID(0, 0); try { edmSimpleKindTypeString = JPATypeConvertor .convertToEdmSimpleType(str.getClass(), null); edmSimpleKindTypeByteArr = JPATypeConvertor .convertToEdmSimpleType(byteArr.getClass(), null); edmSimpleKindTypeLong = JPATypeConvertor .convertToEdmSimpleType(longObj.getClass(), null); edmSimpleKindTypeShort = JPATypeConvertor .convertToEdmSimpleType(shortObj.getClass(), null); edmSimpleKindTypeInteger = JPATypeConvertor .convertToEdmSimpleType(integerObj.getClass(), null); edmSimpleKindTypeDouble = JPATypeConvertor .convertToEdmSimpleType(doubleObj.getClass(), null); edmSimpleKindTypeFloat = JPATypeConvertor .convertToEdmSimpleType(floatObj.getClass(), null); edmSimpleKindTypeBigDecimal = JPATypeConvertor .convertToEdmSimpleType(bigDecimalObj.getClass(), null); edmSimpleKindTypeByte = JPATypeConvertor .convertToEdmSimpleType(byteObj.getClass(), null); edmSimpleKindTypeBoolean = JPATypeConvertor .convertToEdmSimpleType(booleanObj.getClass(), null); edmSimpleKindTypeUUID = JPATypeConvertor .convertToEdmSimpleType(uUID.getClass(), null); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } assertEquals(EdmSimpleTypeKind.String, edmSimpleKindTypeString); assertEquals(EdmSimpleTypeKind.Binary, edmSimpleKindTypeByteArr); assertEquals(EdmSimpleTypeKind.Int64, edmSimpleKindTypeLong); assertEquals(EdmSimpleTypeKind.Int16, edmSimpleKindTypeShort); assertEquals(EdmSimpleTypeKind.Int32, edmSimpleKindTypeInteger); assertEquals(EdmSimpleTypeKind.Double, edmSimpleKindTypeDouble); assertEquals(EdmSimpleTypeKind.Single, edmSimpleKindTypeFloat); assertEquals(EdmSimpleTypeKind.Decimal, edmSimpleKindTypeBigDecimal); assertEquals(EdmSimpleTypeKind.SByte, edmSimpleKindTypeByte); assertEquals(EdmSimpleTypeKind.Boolean, edmSimpleKindTypeBoolean); assertEquals(EdmSimpleTypeKind.Guid, edmSimpleKindTypeUUID); } |
EdmComplexTypeImplProv extends EdmStructuralTypeImplProv implements EdmComplexType { @Override public EdmComplexType getBaseType() throws EdmException { return (EdmComplexType) edmBaseType; } EdmComplexTypeImplProv(final EdmImplProv edm, final ComplexType complexType, final String namespace); @Override EdmComplexType getBaseType(); @Override EdmAnnotations getAnnotations(); } | @Test public void getBaseType() throws Exception { EdmComplexType baseType = edmComplexTypeWithBaseType.getBaseType(); assertNotNull(baseType); assertEquals("barBase", baseType.getName()); assertEquals("namespace", baseType.getNamespace()); } |
EdmComplexTypeImplProv extends EdmStructuralTypeImplProv implements EdmComplexType { @Override public EdmAnnotations getAnnotations() throws EdmException { return new EdmAnnotationsImplProv(structuralType.getAnnotationAttributes(), structuralType.getAnnotationElements()); } EdmComplexTypeImplProv(final EdmImplProv edm, final ComplexType complexType, final String namespace); @Override EdmComplexType getBaseType(); @Override EdmAnnotations getAnnotations(); } | @Test public void getAnnotations() throws Exception { EdmAnnotatable annotatable = edmComplexType; EdmAnnotations annotations = annotatable.getAnnotations(); assertNull(annotations.getAnnotationAttributes()); assertNull(annotations.getAnnotationElements()); } |
EdmAssociationSetEndImplProv implements EdmAssociationSetEnd, EdmAnnotatable { @Override public EdmAnnotations getAnnotations() throws EdmException { return new EdmAnnotationsImplProv(end.getAnnotationAttributes(), end.getAnnotationElements()); } EdmAssociationSetEndImplProv(final AssociationSetEnd end, final EdmEntitySet entitySet); @Override EdmEntitySet getEntitySet(); @Override String getRole(); @Override EdmAnnotations getAnnotations(); } | @Test public void getAnnotations() throws Exception { EdmAnnotatable annotatable = (EdmAnnotatable) edmAssociationSetEnd; EdmAnnotations annotations = annotatable.getAnnotations(); assertNull(annotations.getAnnotationAttributes()); assertNull(annotations.getAnnotationElements()); } |
EdmServiceMetadataImplProv implements EdmServiceMetadata { @Override public List<EdmEntitySetInfo> getEntitySetInfos() throws ODataException { if (entitySetInfos == null) { entitySetInfos = new ArrayList<EdmEntitySetInfo>(); if (schemas == null) { schemas = edmProvider.getSchemas(); } for (Schema schema : schemas) { for (EntityContainer entityContainer : schema.getEntityContainers()) { for (EntitySet entitySet : entityContainer.getEntitySets()) { EdmEntitySetInfo entitySetInfo = new EdmEntitySetInfoImplProv(entitySet, entityContainer); entitySetInfos.add(entitySetInfo); } } } } return entitySetInfos; } EdmServiceMetadataImplProv(final EdmProvider edmProvider); @Override InputStream getMetadata(); @Override String getDataServiceVersion(); @Override List<EdmEntitySetInfo> getEntitySetInfos(); } | @Test public void getEntitySetInfosForEmptyEdmProvider() throws Exception { EdmProvider edmProvider = mock(EdmProvider.class); EdmServiceMetadata serviceMetadata = new EdmServiceMetadataImplProv(edmProvider); List<EdmEntitySetInfo> infos = serviceMetadata.getEntitySetInfos(); assertNotNull(infos); assertEquals(Collections.emptyList(), infos); }
@Test public void getEntitySetInfosForEmptyEdmProviderSchemas() throws Exception { List<Schema> schemas = new ArrayList<Schema>(); EdmProvider edmProvider = mock(EdmProvider.class); when(edmProvider.getSchemas()).thenReturn(schemas); EdmServiceMetadata serviceMetadata = new EdmServiceMetadataImplProv(edmProvider); List<EdmEntitySetInfo> infos = serviceMetadata.getEntitySetInfos(); assertNotNull(infos); assertEquals(Collections.emptyList(), infos); }
@Test public void oneEntitySetOneContainerForInfo() throws Exception { String entitySetUriString = new URI("Employees").toASCIIString(); List<EntitySet> entitySets = new ArrayList<EntitySet>(); EntitySet entitySet = new EntitySet().setName("Employees"); entitySets.add(entitySet); List<EntityContainer> entityContainers = new ArrayList<EntityContainer>(); EntityContainer container = new EntityContainer().setDefaultEntityContainer(true).setName("Container").setEntitySets(entitySets); entityContainers.add(container); List<Schema> schemas = new ArrayList<Schema>(); schemas.add(new Schema().setEntityContainers(entityContainers)); EdmProvider edmProvider = mock(EdmProvider.class); when(edmProvider.getSchemas()).thenReturn(schemas); EdmServiceMetadata serviceMetadata = new EdmServiceMetadataImplProv(edmProvider); List<EdmEntitySetInfo> infos = serviceMetadata.getEntitySetInfos(); assertNotNull(infos); assertEquals(1, infos.size()); assertEquals(infos.get(0).getEntitySetName(), "Employees"); assertEquals(infos.get(0).getEntityContainerName(), "Container"); assertEquals(infos.get(0).getEntitySetUri().toASCIIString(), entitySetUriString); assertTrue(infos.get(0).isDefaultEntityContainer()); }
@Test public void twoEntitySetsOneContainerForInfo() throws Exception { List<EntitySet> entitySets = new ArrayList<EntitySet>(); EntitySet entitySet = new EntitySet().setName("Employees"); entitySets.add(entitySet); entitySets.add(entitySet); List<EntityContainer> entityContainers = new ArrayList<EntityContainer>(); EntityContainer container = new EntityContainer().setDefaultEntityContainer(true).setName("Container").setEntitySets(entitySets); entityContainers.add(container); List<Schema> schemas = new ArrayList<Schema>(); schemas.add(new Schema().setEntityContainers(entityContainers)); EdmProvider edmProvider = mock(EdmProvider.class); when(edmProvider.getSchemas()).thenReturn(schemas); EdmServiceMetadata serviceMetadata = new EdmServiceMetadataImplProv(edmProvider); List<EdmEntitySetInfo> infos = serviceMetadata.getEntitySetInfos(); assertNotNull(infos); assertEquals(2, infos.size()); }
@Test public void twoContainersWithOneEntitySetEachForInfo() throws Exception { String entitySetUriString = new URI("Employees").toASCIIString(); String entitySetUriString2 = new URI("Container2.Employees").toASCIIString(); List<EntitySet> entitySets = new ArrayList<EntitySet>(); EntitySet entitySet = new EntitySet().setName("Employees"); entitySets.add(entitySet); List<EntityContainer> entityContainers = new ArrayList<EntityContainer>(); EntityContainer container = new EntityContainer().setDefaultEntityContainer(true).setName("Container").setEntitySets(entitySets); entityContainers.add(container); EntityContainer container2 = new EntityContainer().setDefaultEntityContainer(false).setName("Container2").setEntitySets(entitySets); entityContainers.add(container2); List<Schema> schemas = new ArrayList<Schema>(); schemas.add(new Schema().setEntityContainers(entityContainers)); EdmProvider edmProvider = mock(EdmProvider.class); when(edmProvider.getSchemas()).thenReturn(schemas); EdmServiceMetadata serviceMetadata = new EdmServiceMetadataImplProv(edmProvider); List<EdmEntitySetInfo> infos = serviceMetadata.getEntitySetInfos(); assertNotNull(infos); assertEquals(2, infos.size()); assertEquals(infos.get(0).getEntitySetName(), "Employees"); assertEquals(infos.get(0).getEntityContainerName(), "Container"); assertEquals(infos.get(0).getEntitySetUri().toASCIIString(), entitySetUriString); assertTrue(infos.get(0).isDefaultEntityContainer()); assertEquals(infos.get(1).getEntitySetName(), "Employees"); assertEquals(infos.get(1).getEntityContainerName(), "Container2"); assertEquals(infos.get(1).getEntitySetUri().toASCIIString(), entitySetUriString2); assertFalse(infos.get(1).isDefaultEntityContainer()); }
@Test public void oneEntitySetsOneContainerTwoSchemadForInfo() throws Exception { List<EntitySet> entitySets = new ArrayList<EntitySet>(); EntitySet entitySet = new EntitySet().setName("Employees"); entitySets.add(entitySet); List<EntityContainer> entityContainers = new ArrayList<EntityContainer>(); EntityContainer container = new EntityContainer().setDefaultEntityContainer(true).setName("Container").setEntitySets(entitySets); entityContainers.add(container); List<Schema> schemas = new ArrayList<Schema>(); schemas.add(new Schema().setEntityContainers(entityContainers)); schemas.add(new Schema().setEntityContainers(entityContainers)); EdmProvider edmProvider = mock(EdmProvider.class); when(edmProvider.getSchemas()).thenReturn(schemas); EdmServiceMetadata serviceMetadata = new EdmServiceMetadataImplProv(edmProvider); List<EdmEntitySetInfo> infos = serviceMetadata.getEntitySetInfos(); assertNotNull(infos); assertEquals(2, infos.size()); } |
EdmServiceMetadataImplProv implements EdmServiceMetadata { @Override public String getDataServiceVersion() throws ODataException { if (schemas == null) { schemas = edmProvider.getSchemas(); } if (dataServiceVersion == null) { dataServiceVersion = ODataServiceVersion.V10; if (schemas != null) { for (Schema schema : schemas) { List<EntityType> entityTypes = schema.getEntityTypes(); if (entityTypes != null) { for (EntityType entityType : entityTypes) { List<Property> properties = entityType.getProperties(); if (properties != null) { for (Property property : properties) { if (property.getCustomizableFeedMappings() != null) { if (property.getCustomizableFeedMappings().getFcKeepInContent() != null) { if (!property.getCustomizableFeedMappings().getFcKeepInContent()) { dataServiceVersion = ODataServiceVersion.V20; return dataServiceVersion; } } } } if (entityType.getCustomizableFeedMappings() != null) { if (entityType.getCustomizableFeedMappings().getFcKeepInContent() != null) { if (entityType.getCustomizableFeedMappings().getFcKeepInContent()) { dataServiceVersion = ODataServiceVersion.V20; return dataServiceVersion; } } } } } } } } } return dataServiceVersion; } EdmServiceMetadataImplProv(final EdmProvider edmProvider); @Override InputStream getMetadata(); @Override String getDataServiceVersion(); @Override List<EdmEntitySetInfo> getEntitySetInfos(); } | @Test public void dataServiceVersion() throws Exception { EdmProvider edmProvider = mock(EdmProvider.class); EdmImplProv edmImplProv = new EdmImplProv(edmProvider); EdmServiceMetadata serviceMetadata = edmImplProv.getServiceMetadata(); assertEquals("1.0", serviceMetadata.getDataServiceVersion()); } |
JPAEdmMappingModelService implements JPAEdmMappingModelAccess { @Override public void loadMappingModel() { if (mappingModelExists) { JAXBContext context; try { context = JAXBContext.newInstance(JPAEdmMappingModel.class); Unmarshaller unmarshaller = context.createUnmarshaller(); InputStream is = loadMappingModelInputStream(); if (is == null) { mappingModelExists = false; return; } mappingModel = (JPAEdmMappingModel) unmarshaller.unmarshal(is); if (mappingModel != null) { mappingModelExists = true; } } catch (JAXBException e) { mappingModelExists = false; ODataJPAModelException.throwException( ODataJPAModelException.GENERAL, e); } } } JPAEdmMappingModelService(final ODataJPAContext ctx); @Override void loadMappingModel(); @Override boolean isMappingModelExists(); @Override JPAEdmMappingModel getJPAEdmMappingModel(); @Override String mapJPAPersistenceUnit(final String persistenceUnitName); @Override String mapJPAEntityType(final String jpaEntityTypeName); @Override String mapJPAEntitySet(final String jpaEntityTypeName); @Override String mapJPAAttribute(final String jpaEntityTypeName,
final String jpaAttributeName); @Override String mapJPARelationship(final String jpaEntityTypeName,
final String jpaRelationshipName); @Override String mapJPAEmbeddableType(final String jpaEmbeddableTypeName); @Override String mapJPAEmbeddableTypeAttribute(final String jpaEmbeddableTypeName,
final String jpaAttributeName); @Override boolean checkExclusionOfJPAEntityType(final String jpaEntityTypeName); @Override boolean checkExclusionOfJPAAttributeType(final String jpaEntityTypeName,
final String jpaAttributeName); @Override boolean checkExclusionOfJPAEmbeddableType(
final String jpaEmbeddableTypeName); @Override boolean checkExclusionOfJPAEmbeddableAttributeType(
final String jpaEmbeddableTypeName, final String jpaAttributeName); } | @Test public void testLoadMappingModel() { VARIANT_MAPPING_FILE = 1; loadMappingModel(); assertTrue(isMappingModelExists()); } |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.