@Test public void binaryIntegerOperations() { ODataRetrieveResponse<ClientEntitySet> result = sendRequest(ES_TWO_KEY_NAV, "PropertyInt16 add 1 eq (1 sub 3) div 2 mul 3 add 7"); assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); assertShortOrInt(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); }
@Test public void hourFunctionDateTimeOffset() { ODataRetrieveResponse<ClientEntitySet> result = sendRequest(ES_ALL_PRIM, "hour(PropertyDateTimeOffset) eq 7"); assertEquals(2, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); assertShortOrInt( 32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(1); assertShortOrInt( -32768, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); }
@Test public void unaryMinusOperatorDecimal() { ODataRetrieveResponse<ClientEntitySet> result = sendRequest(ES_TWO_KEY_NAV, "PropertyInt16 gt -2.0 add --3.0"); assertEquals(2, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); assertShortOrInt(2, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(1); assertShortOrInt(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); }
@Test public void endsWith() { ODataRetrieveResponse<ClientEntitySet> result = sendRequest(ES_ALL_PRIM, "endswith(PropertyString,'values')"); assertEquals(2, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); assertShortOrInt( 32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(1); assertShortOrInt( -32768, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); }
@Test public void round() { ODataRetrieveResponse<ClientEntitySet> result = sendRequest(ES_TWO_KEY_NAV, "PropertyInt16 eq round(2.5)"); assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); assertShortOrInt(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); result = sendRequest(ES_TWO_KEY_NAV, "PropertyInt16 eq round(2.4)"); assertEquals(1, result.getBody().getEntities().size()); clientEntity = result.getBody().getEntities().get(0); assertShortOrInt(2, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); result = sendRequest(ES_TWO_KEY_NAV, "PropertyInt16 eq round(2.6)"); assertEquals(1, result.getBody().getEntities().size()); clientEntity = result.getBody().getEntities().get(0); assertShortOrInt(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); result = sendRequest(ES_TWO_KEY_NAV, "PropertyInt16 eq round(3.1)"); assertEquals(1, result.getBody().getEntities().size()); clientEntity = result.getBody().getEntities().get(0); assertShortOrInt(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); }
@Test public void notOperator() { ODataRetrieveResponse<ClientEntitySet> result = sendRequest(ES_TWO_KEY_NAV, "not (PropertyInt16 eq 1)"); assertEquals(2, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); assertShortOrInt(2, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(1); assertShortOrInt(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); }
@Test public void clientEscaping() { final String filter = getClient() .getFilterFactory() .eq( getClient().getFilterFactory().getArgFactory().property("PropertyString"), getClient() .getFilterFactory() .getArgFactory() .literal("First Resource - positive values")) .build(); final URI uri = getClient() .newURIBuilder(SERVICE_URI) .appendEntitySetSegment(ES_ALL_PRIM) .filter(filter) .build(); ODataEntitySetRequest<ClientEntitySet> request = getClient().getRetrieveRequestFactory().getEntitySetRequest(uri); setCookieHeader(request); final ODataRetrieveResponse<ClientEntitySet> response = request.execute(); saveCookieHeader(response); assertEquals(1, response.getBody().getEntities().size()); ClientEntity clientEntity = response.getBody().getEntities().get(0); assertShortOrInt( 32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); }
@Test public void numericPromotionToInt64() { ODataRetrieveResponse<ClientEntitySet> result = sendRequest(ES_ALL_PRIM, "PropertyInt64 eq 0"); assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); assertShortOrInt(0, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); }
@Test public void fractionalsecondsDateTimeOffset() { ODataRetrieveResponse<ClientEntitySet> response = sendRequest( ES_COMP_ALL_PRIM, "fractionalseconds(PropertyComp/PropertyDateTimeOffset) eq 0.1234567"); assertEquals(2, response.getBody().getEntities().size()); ClientEntity clientEntity = response.getBody().getEntities().get(0); assertShortOrInt( 32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); assertEquals("W/\"32767\"", clientEntity.getETag()); clientEntity = response.getBody().getEntities().get(1); assertShortOrInt(0, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); assertEquals("W/\"0\"", clientEntity.getETag()); }
@Test public void binaryOperationIntegerDecimalWithPromotion() { String filterString = "" + "PropertyInt16 mod 2 eq " // Choose mod 2 == 1 => { 1, 3, .. } + "(((5 sub 1) div 5) " // Integer Division 4 / 5 == 0 + "add 1) " // 0 + 1 = 1 + "and " + "PropertyComp/PropertyInt16 eq " // Complex Property + "5.5 mul 2"; // Single * Int16 => Single => Int16 eq Single => Single eq Single ODataRetrieveResponse<ClientEntitySet> result = sendRequest(ES_TWO_KEY_NAV, filterString); assertEquals(3, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); assertShortOrInt(1, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); assertShortOrInt( 11, clientEntity .getProperty("PropertyComp") .getComplexValue() .get("PropertyInt16") .getPrimitiveValue() .toValue()); clientEntity = result.getBody().getEntities().get(1); assertShortOrInt(1, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); assertEquals("2", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); assertShortOrInt( 11, clientEntity .getProperty("PropertyComp") .getComplexValue() .get("PropertyInt16") .getPrimitiveValue() .toValue()); clientEntity = result.getBody().getEntities().get(2); assertShortOrInt(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); assertShortOrInt( 11, clientEntity .getProperty("PropertyComp") .getComplexValue() .get("PropertyInt16") .getPrimitiveValue() .toValue()); }
@Test public void dateSubDate() { ODataRetrieveResponse<ClientEntitySet> response = sendRequest(ES_ALL_PRIM, "PropertyDuration eq 2012-12-04 sub 2012-12-04"); assertEquals(1, response.getBody().getEntities().size()); final ClientEntity clientEntity = response.getBody().getEntities().get(0); assertShortOrInt(0, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); }
@Test public void stringProperty() { ODataRetrieveResponse<ClientEntitySet> result = sendRequest(ES_TWO_KEY_NAV, "PropertyString eq '2'"); assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); assertEquals("2", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); }
@Test public void dayFunctionDate() { ODataRetrieveResponse<ClientEntitySet> result = sendRequest(ES_ALL_PRIM, "day(PropertyDate) eq 5"); assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); assertShortOrInt( -32768, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); }
@Test public void decimalDiv() { ODataRetrieveResponse<ClientEntitySet> result = sendRequest(ES_ALL_PRIM, "PropertyDouble eq 0 sub (358000 div 2)"); assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); assertShortOrInt( -32768, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); }
@Test public void toUpper() { ODataRetrieveResponse<ClientEntitySet> result = sendRequest(ES_ALL_PRIM, "contains(PropertyString,concat(toupper('f'),'irst'))"); assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); assertShortOrInt( 32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); }
@Test public void timeOfDayLiteral() { ODataRetrieveResponse<ClientEntitySet> result = sendRequest(ES_ALL_PRIM, "PropertyTimeOfDay eq 03:26:05"); assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); assertShortOrInt( 32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); }
@Test public void durationSubDuration() { ODataRetrieveResponse<ClientEntitySet> response = sendRequest(ES_ALL_PRIM, "PropertyDuration sub duration'PT2S' eq duration'PT4S'"); assertEquals(1, response.getBody().getEntities().size()); final ClientEntity clientEntity = response.getBody().getEntities().get(0); assertShortOrInt( 32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); }
@Test public void indexOf() { ODataRetrieveResponse<ClientEntitySet> result = sendRequest(ES_ALL_PRIM, "indexof(PropertyString,'positive') eq 17"); assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); assertShortOrInt( 32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); }
@Test public void dateAddDuration() { ODataRetrieveResponse<ClientEntitySet> response = sendRequest(ES_ALL_PRIM, "PropertyDate eq 2012-12-01 add duration'P1DT27H16M23S'"); assertEquals(1, response.getBody().getEntities().size()); final ClientEntity clientEntity = response.getBody().getEntities().get(0); assertShortOrInt( 32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); }
@Test public void trim() { ODataRetrieveResponse<ClientEntitySet> result = sendRequest(ES_ALL_PRIM, "trim(substring(PropertyString,0,6)) eq 'First'"); assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); assertShortOrInt( 32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); }
@Test public void booleanLiteral() { ODataRetrieveResponse<ClientEntitySet> response = sendRequest(ES_ALL_PRIM, "PropertyBoolean eq false"); assertEquals(2, response.getBody().getEntities().size()); ClientEntity clientEntity = response.getBody().getEntities().get(0); assertShortOrInt( -32768, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); clientEntity = response.getBody().getEntities().get(1); assertShortOrInt(0, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); response = sendRequest(ES_ALL_PRIM, "PropertyBoolean eq true"); assertEquals(1, response.getBody().getEntities().size()); clientEntity = response.getBody().getEntities().get(0); assertShortOrInt( 32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); }
@Test public void dateTimeOffsetLiteral() { ODataRetrieveResponse<ClientEntitySet> result = sendRequest(ES_ALL_PRIM, "PropertyDateTimeOffset eq 2012-12-03T07:16:23Z"); assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); assertShortOrInt( 32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); }
@Test public void secondFunctionTimeOfDay() { ODataRetrieveResponse<ClientEntitySet> response = sendRequest(ES_ALL_PRIM, "second(PropertyTimeOfDay) eq 14"); assertEquals(1, response.getBody().getEntities().size()); ClientEntity clientEntity = response.getBody().getEntities().get(0); assertShortOrInt( -32768, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); }
@Test public void int64Literal() { long value = Integer.MAX_VALUE + 1L; ODataRetrieveResponse<ClientEntitySet> result = sendRequest(ES_ALL_PRIM, "PropertyInt64 gt " + value); assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); assertShortOrInt( 32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); }
@Test public void doubleLiteral() { Double value = -17900000000000000000.0; ODataRetrieveResponse<ClientEntitySet> result = sendRequest(ES_ALL_PRIM, "PropertyDouble le " + value.toString()); assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); assertShortOrInt( 32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); }
@Test public void substringStartAndEndGiven() { ODataRetrieveResponse<ClientEntitySet> result = sendRequest( ES_ALL_PRIM, "substring(PropertyString,length('First') add 1,8) eq ('Resource')"); assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); assertShortOrInt( 32767, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); }
@Test public void substringStartGiven() { ODataRetrieveResponse<ClientEntitySet> result = sendRequest( ES_TWO_KEY_NAV, "substring(PropertyComp/PropertyComp/PropertyString,6) eq 'Value'"); assertEquals(4, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); assertShortOrInt(1, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(1); assertShortOrInt(1, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); assertEquals("2", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(2); assertShortOrInt(2, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(3); assertShortOrInt(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); }
@Test public void booleanOperator() { ODataRetrieveResponse<ClientEntitySet> result = sendRequest(ES_TWO_KEY_NAV, "PropertyString eq '2' and PropertyInt16 eq 1"); assertEquals(1, result.getBody().getEntities().size()); ClientEntity clientEntity = result.getBody().getEntities().get(0); assertShortOrInt(1, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); assertEquals("2", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); result = sendRequest(ES_TWO_KEY_NAV, "PropertyString eq '2' or PropertyInt16 eq 1"); assertEquals(2, result.getBody().getEntities().size()); clientEntity = result.getBody().getEntities().get(0); assertShortOrInt(1, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); clientEntity = result.getBody().getEntities().get(1); assertShortOrInt(1, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue()); assertEquals("2", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue()); result = sendRequest( ES_MIX_ENUM_DEF_COLL_COMP, "PropertyEnumString eq Namespace1_Alias.ENString'String2'"); assertTrue(result.getBody().getEntities().isEmpty()); }