src/androidTest/java/de/blau/android/layer/LayerDialogTest.java
/**
     * Test querying and adding a layer from a WMS endpoint
     */
Test querying and adding a layer from a WMS endpoint
Test querying and adding a layer from a WMS endpoint
@Test
    public void wmsEndpoint() {
        assertTrue(TestUtils.clickResource(device, true, device.getCurrentPackageName() + ":id/layers", true));
        assertTrue(TestUtils.clickResource(device, true, device.getCurrentPackageName() + ":id/add", true));
        TestUtils.scrollToEnd(false);
        assertTrue(TestUtils.clickText(device, false, main.getString(R.string.add_imagery_from_wms_endpoint), true));
        assertTrue(TestUtils.findText(device, false, main.getString(R.string.wms_endpoints_title)));
        assertTrue(TestUtils.clickResource(device, true, device.getCurrentPackageName() + ":id/add", true));
        MockWebServerPlus wmsServer = null;
        try {
            wmsServer = new MockWebServerPlus();
            String urlString = wmsServer.url("").toString();
            UiObject name = device.findObject(new UiSelector().resourceId(device.getCurrentPackageName() + ":id/name"));
            final String endpointName = "Test WMS Endpoint";
            try {
                name.setText(endpointName);
            } catch (UiObjectNotFoundException e) {
                fail(e.getMessage());
            }
            UiObject url = device.findObject(new UiSelector().resourceId(device.getCurrentPackageName() + ":id/url"));
            try {
                url.setText(urlString);
            } catch (UiObjectNotFoundException e) {
                fail(e.getMessage());
            }
            assertTrue(TestUtils.clickText(device, false, main.getString(R.string.save), true));
            try (TileLayerDatabase db = new TileLayerDatabase(ApplicationProvider.getApplicationContext())) {
                TileLayerSource tls = TileLayerDatabase.getLayerWithUrl(main, db.getReadableDatabase(), urlString);
                assertNotNull(tls);
                assertEquals(endpointName, tls.getName());
                assertEquals(TileLayerSource.TYPE_WMS_ENDPOINT, tls.getType());
            }
            wmsServer.enqueue("wms_capabilities");
            TestUtils.scrollTo(endpointName, false);
            assertTrue(TestUtils.clickText(device, false, endpointName, true, false));
            assertTrue(TestUtils.findText(device, false, main.getString(R.string.select_layer_title)));
            UiScrollable appView = new UiScrollable(new UiSelector().scrollable(true));
            try {
                appView.setSwipeDeadZonePercentage(0.4);
                appView.scrollIntoView(new UiSelector().textContains("Capas"));
            } catch (UiObjectNotFoundException e) {
            }
            assertTrue(TestUtils.clickText(device, false, "Capas", true));
            UiObject top = device.findObject(new UiSelector().resourceId(device.getCurrentPackageName() + ":id/top"));
            try {
                top.setText("85");
            } catch (UiObjectNotFoundException e) {
                fail(e.getMessage());
            }
            UiObject bottom = device.findObject(new UiSelector().resourceId(device.getCurrentPackageName() + ":id/bottom"));
            try {
                bottom.setText("85");
            } catch (UiObjectNotFoundException e) {
                fail(e.getMessage());
            }
            assertTrue(TestUtils.clickText(device, false, main.getString(R.string.save), true));
            assertTrue(TestUtils.clickText(device, false, main.getString(R.string.done), true));
            assertTrue(TestUtils.clickText(device, false, main.getString(R.string.done), true));
            assertTrue(TestUtils.clickText(device, false, main.getString(R.string.done), true));
        } finally {
            try {
                wmsServer.server().shutdown();
            } catch (IOException e) {
            }
        }
    }
@ Test public void wmsEndpoint ( ) { assertTrue ( TestUtils . clickResource ( device , true , device . getCurrentPackageName ( ) + ":id/layers" , true ) ) ; assertTrue ( TestUtils . clickResource ( device , true , device . getCurrentPackageName ( ) + ":id/add" , true ) ) ; TestUtils . scrollToEnd ( false ) ; assertTrue ( TestUtils . clickText ( device , false , main . getString ( R . string . add_imagery_from_wms_endpoint ) , true ) ) ; assertTrue ( TestUtils . findText ( device , false , main . getString ( R . string . wms_endpoints_title ) ) ) ; assertTrue ( TestUtils . clickResource ( device , true , device . getCurrentPackageName ( ) + ":id/add" , true ) ) ; MockWebServerPlus wmsServer = null ; try { wmsServer = new MockWebServerPlus ( ) ; String urlString = wmsServer . url ( "" ) . toString ( ) ; UiObject name = device . findObject ( new UiSelector ( ) . resourceId ( device . getCurrentPackageName ( ) + ":id/name" ) ) ; final String endpointName = "Test WMS Endpoint" ; try { name . setText ( endpointName ) ; } catch ( UiObjectNotFoundException e ) { fail ( e . getMessage ( ) ) ; } UiObject url = device . findObject ( new UiSelector ( ) . resourceId ( device . getCurrentPackageName ( ) + ":id/url" ) ) ; try { url . setText ( urlString ) ; } catch ( UiObjectNotFoundException e ) { fail ( e . getMessage ( ) ) ; } assertTrue ( TestUtils . clickText ( device , false , main . getString ( R . string . save ) , true ) ) ; try ( TileLayerDatabase db = new TileLayerDatabase ( ApplicationProvider . getApplicationContext ( ) ) ) { TileLayerSource tls = TileLayerDatabase . getLayerWithUrl ( main , db . getReadableDatabase ( ) , urlString ) ; assertNotNull ( tls ) ; assertEquals ( endpointName , tls . getName ( ) ) ; assertEquals ( TileLayerSource . TYPE_WMS_ENDPOINT , tls . getType ( ) ) ; } wmsServer . enqueue ( "wms_capabilities" ) ; TestUtils . scrollTo ( endpointName , false ) ; assertTrue ( TestUtils . clickText ( device , false , endpointName , true , false ) ) ; assertTrue ( TestUtils . findText ( device , false , main . getString ( R . string . select_layer_title ) ) ) ; UiScrollable appView = new UiScrollable ( new UiSelector ( ) . scrollable ( true ) ) ; try { appView . setSwipeDeadZonePercentage ( 0.4 ) ; appView . scrollIntoView ( new UiSelector ( ) . textContains ( "Capas" ) ) ; } catch ( UiObjectNotFoundException e ) { } assertTrue ( TestUtils . clickText ( device , false , "Capas" , true ) ) ; UiObject top = device . findObject ( new UiSelector ( ) . resourceId ( device . getCurrentPackageName ( ) + ":id/top" ) ) ; try { top . setText ( "85" ) ; } catch ( UiObjectNotFoundException e ) { fail ( e . getMessage ( ) ) ; } UiObject bottom = device . findObject ( new UiSelector ( ) . resourceId ( device . getCurrentPackageName ( ) + ":id/bottom" ) ) ; try { bottom . setText ( "85" ) ; } catch ( UiObjectNotFoundException e ) { fail ( e . getMessage ( ) ) ; } assertTrue ( TestUtils . clickText ( device , false , main . getString ( R . string . save ) , true ) ) ; assertTrue ( TestUtils . clickText ( device , false , main . getString ( R . string . done ) , true ) ) ; assertTrue ( TestUtils . clickText ( device , false , main . getString ( R . string . done ) , true ) ) ; assertTrue ( TestUtils . clickText ( device , false , main . getString ( R . string . done ) , true ) ) ; } finally { try { wmsServer . server ( ) . shutdown ( ) ; } catch ( IOException e ) { } } }
Test querying and adding a layer from a WMS endpoint
Test querying and adding a layer from a WMS endpoint