| /******************************************************************************** |
| * Copyright (c) 2015-2019 Contributors to the Eclipse Foundation |
| * |
| * See the NOTICE file(s) distributed with this work for additional |
| * information regarding copyright ownership. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v. 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0. |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| ********************************************************************************/ |
| |
| package org.eclipse.mdm.businessobjects.control; |
| |
| import static org.assertj.core.api.Assertions.assertThat; |
| import static org.mockito.ArgumentMatchers.any; |
| import static org.mockito.ArgumentMatchers.eq; |
| import static org.mockito.Mockito.when; |
| |
| import java.util.Arrays; |
| import java.util.List; |
| |
| import org.eclipse.mdm.api.base.adapter.EntityType; |
| import org.eclipse.mdm.api.base.model.Value; |
| import org.eclipse.mdm.api.base.model.ValueType; |
| import org.eclipse.mdm.api.base.query.Filter; |
| import org.eclipse.mdm.query.boundary.QueryServiceTest; |
| import org.junit.Test; |
| import org.mockito.invocation.InvocationOnMock; |
| import org.mockito.stubbing.Answer; |
| |
| public class FilterParserTest { |
| |
| @Test |
| public void testParseFilterString() throws Exception { |
| EntityType test = QueryServiceTest.mockEntity("env2", "Test"); |
| EntityType pool = QueryServiceTest.mockEntity("env2", "Pool"); |
| when(test.getAttribute("Name").createValue(eq(""), any())).thenAnswer(new Answer<Value>() { |
| |
| @Override |
| public Value answer(InvocationOnMock invocation) throws Throwable { |
| return ValueType.STRING.create("env2", invocation.getArgument(0), true, invocation.getArgument(1)); |
| } |
| }); |
| |
| List<EntityType> possibleEntityTypes = Arrays.asList(test, pool); |
| |
| Filter filter = FilterParser.parseFilterString(possibleEntityTypes, "Test.Name lk \"With\\\"quote\\\"\""); |
| assertThat(filter).isEqualTo(Filter.and().name(test, "With\"quote\"")); |
| |
| Filter filter2 = FilterParser.parseFilterString(possibleEntityTypes, "Test.Name lk 'With\"quote\"'"); |
| assertThat(filter2).isEqualTo(Filter.and().name(test, "With\"quote\"")); |
| |
| Filter filter3 = FilterParser.parseFilterString(possibleEntityTypes, "Test.Name lk 'With\\'quote\\''"); |
| assertThat(filter3).isEqualTo(Filter.and().name(test, "With'quote'")); |
| |
| Filter filter4 = FilterParser.parseFilterString(possibleEntityTypes, "Test.Name lk \"With'quote'\""); |
| assertThat(filter4).isEqualTo(Filter.and().name(test, "With'quote'")); |
| } |
| |
| } |