Search in sources :

Example 1 with ContentUriChecker

use of com.abubusoft.kripton.processor.sqlite.grammars.uri.ContentUriChecker in project kripton by xcesco.

the class TestUriChecker method testAuthorityWithVariableInPathError.

@Test(expected = KriptonProcessorException.class)
public void testAuthorityWithVariableInPathError() {
    String input = "content://androi.authority/test/${ input0 }/";
    ContentUriChecker checker = ContentUriChecker.getInstance();
    // check bind parameters
    {
        List<ContentUriPlaceHolder> aspected = new ArrayList<>();
        aspected.add(new ContentUriPlaceHolder(1, "input0"));
        aspected.add(new ContentUriPlaceHolder(2, "input1"));
        List<ContentUriPlaceHolder> actual = checker.extract(input);
        checkCollectionExactly(actual, aspected);
    }
}
Also used : ContentUriChecker(com.abubusoft.kripton.processor.sqlite.grammars.uri.ContentUriChecker) ContentUriPlaceHolder(com.abubusoft.kripton.processor.sqlite.grammars.uri.ContentUriPlaceHolder) ArrayList(java.util.ArrayList) List(java.util.List) BaseProcessorTest(base.BaseProcessorTest) Test(org.junit.Test)

Example 2 with ContentUriChecker

use of com.abubusoft.kripton.processor.sqlite.grammars.uri.ContentUriChecker in project kripton by xcesco.

the class TestUriChecker method testExtractor.

@Test
public void testExtractor() throws Throwable {
    String input = "content://androi.authority/master/${ master }/detail/${detail}/subdetail/${subdetail}";
    log(input);
    ContentUriChecker checker = ContentUriChecker.getInstance();
    Map<String, ContentUriPlaceHolder> parameters = checker.extractAsMap(input);
    String actual = checker.replace(input, new UriPlaceHolderReplacerListener() {

        @Override
        public String onParameterName(int pathSegmentIndex, String name) {
            log("segment : %s, name: %s", pathSegmentIndex, name);
            return "?";
        }
    });
    String expected = "content://androi.authority/master/?/detail/?/subdetail/?";
    assertEquals(actual, expected);
    log(expected);
    // log(""+expected.split("/").length);
    ContentProviderURIParamsExtractor extractor = new ContentProviderURIParamsExtractor(expected, input.split("/").length);
    for (ContentUriPlaceHolder item : parameters.values()) {
        assertTrue(extractor.getPathSegment(item.pathSegmentIndex).equals("?"));
    }
}
Also used : ContentUriChecker(com.abubusoft.kripton.processor.sqlite.grammars.uri.ContentUriChecker) ContentUriPlaceHolder(com.abubusoft.kripton.processor.sqlite.grammars.uri.ContentUriPlaceHolder) UriPlaceHolderReplacerListener(com.abubusoft.kripton.processor.sqlite.grammars.uri.ContentUriChecker.UriPlaceHolderReplacerListener) ContentProviderURIParamsExtractor(com.abubusoft.kripton.android.sqlite.ContentProviderURIParamsExtractor) BaseProcessorTest(base.BaseProcessorTest) Test(org.junit.Test)

Example 3 with ContentUriChecker

use of com.abubusoft.kripton.processor.sqlite.grammars.uri.ContentUriChecker in project kripton by xcesco.

the class TestUriChecker method testExtractParametersFromPath.

@Test
public void testExtractParametersFromPath() {
    String input = "test/${ input }/ test /${ detail.id}";
    ContentUriChecker checker = ContentUriChecker.getInstance();
    {
        List<ContentUriPlaceHolder> result = checker.extractFromPath(input);
        for (ContentUriPlaceHolder item : result) {
            log(item.toString());
        }
        checkList(result, new ContentUriPlaceHolder(1, "input"), new ContentUriPlaceHolder(3, "detail.id"));
    }
    {
        List<ContentUriPlaceHolder> result = checker.extractFromPath(input);
        for (ContentUriPlaceHolder item : result) {
            log(item.toString());
        }
        checkList(result, new ContentUriPlaceHolder(1, "input"), new ContentUriPlaceHolder(3, "detail.id"));
    }
}
Also used : ContentUriChecker(com.abubusoft.kripton.processor.sqlite.grammars.uri.ContentUriChecker) ContentUriPlaceHolder(com.abubusoft.kripton.processor.sqlite.grammars.uri.ContentUriPlaceHolder) ArrayList(java.util.ArrayList) List(java.util.List) BaseProcessorTest(base.BaseProcessorTest) Test(org.junit.Test)

Example 4 with ContentUriChecker

use of com.abubusoft.kripton.processor.sqlite.grammars.uri.ContentUriChecker in project kripton by xcesco.

the class TestUriChecker method testERROR.

/**
 * <p>
 * OK
 * </p>
 *
 * @throws Throwable
 */
@Test(expected = KriptonProcessorException.class)
public void testERROR() throws Throwable {
    String input = "content://androi.authority/test/${ input }/";
    log(input);
    ContentUriChecker checker = ContentUriChecker.getInstance();
    checker.verify(input);
}
Also used : ContentUriChecker(com.abubusoft.kripton.processor.sqlite.grammars.uri.ContentUriChecker) BaseProcessorTest(base.BaseProcessorTest) Test(org.junit.Test)

Example 5 with ContentUriChecker

use of com.abubusoft.kripton.processor.sqlite.grammars.uri.ContentUriChecker in project kripton by xcesco.

the class TestUriChecker method testReplaceAuthorityWithVariable.

@Test
public void testReplaceAuthorityWithVariable() {
    String input = "content://androi.authority/test/${field0}/${field1}";
    String expected = "content://androi.authority/test/#/*";
    log(input);
    ContentUriChecker checker = ContentUriChecker.getInstance();
    // verify sql
    checker.verify(input);
    // check bind parameters
    {
        String actual = checker.replace(input, new UriPlaceHolderReplacerListener() {

            @Override
            public String onParameterName(int pathSegmentIndex, String name) {
                log("segment :" + pathSegmentIndex);
                if (name.endsWith("0")) {
                    return "#";
                }
                ;
                return "*";
            }
        });
        assertEquals(actual, expected);
        {
            List<ContentUriPlaceHolder> aspectedHolders = new ArrayList<>();
            aspectedHolders.add(new ContentUriPlaceHolder(1, "field0"));
            aspectedHolders.add(new ContentUriPlaceHolder(2, "field1"));
            List<ContentUriPlaceHolder> actualHolders = checker.extract(input);
            checkCollectionExactly(aspectedHolders, actualHolders);
        }
    }
}
Also used : ContentUriChecker(com.abubusoft.kripton.processor.sqlite.grammars.uri.ContentUriChecker) ContentUriPlaceHolder(com.abubusoft.kripton.processor.sqlite.grammars.uri.ContentUriPlaceHolder) UriPlaceHolderReplacerListener(com.abubusoft.kripton.processor.sqlite.grammars.uri.ContentUriChecker.UriPlaceHolderReplacerListener) ArrayList(java.util.ArrayList) BaseProcessorTest(base.BaseProcessorTest) Test(org.junit.Test)

Aggregations

BaseProcessorTest (base.BaseProcessorTest)9 ContentUriChecker (com.abubusoft.kripton.processor.sqlite.grammars.uri.ContentUriChecker)9 Test (org.junit.Test)9 ContentUriPlaceHolder (com.abubusoft.kripton.processor.sqlite.grammars.uri.ContentUriPlaceHolder)7 ArrayList (java.util.ArrayList)6 List (java.util.List)5 UriPlaceHolderReplacerListener (com.abubusoft.kripton.processor.sqlite.grammars.uri.ContentUriChecker.UriPlaceHolderReplacerListener)3 ContentProviderURIParamsExtractor (com.abubusoft.kripton.android.sqlite.ContentProviderURIParamsExtractor)1