|
| 1 | +package mil.nga.giat.geowave.cli.geoserver; |
| 2 | + |
| 3 | +import mil.nga.giat.geowave.cli.geoserver.GeoServerConfig; |
| 4 | +import mil.nga.giat.geowave.cli.geoserver.GeoServerRestClient; |
| 5 | +import org.junit.Assert; |
| 6 | +import org.junit.Before; |
| 7 | +import org.junit.Test; |
| 8 | +import org.mockito.Mockito; |
| 9 | + |
| 10 | +import javax.ws.rs.client.Entity; |
| 11 | +import javax.ws.rs.client.Invocation; |
| 12 | +import javax.ws.rs.client.WebTarget; |
| 13 | +import javax.ws.rs.core.Response; |
| 14 | + |
| 15 | +public class GeoServerRestClientTest |
| 16 | +{ |
| 17 | + WebTarget webTarget; |
| 18 | + GeoServerConfig config; |
| 19 | + GeoServerRestClient client; |
| 20 | + |
| 21 | + private WebTarget mockedWebTarget() { |
| 22 | + WebTarget webTarget = Mockito.mock(WebTarget.class); |
| 23 | + Invocation.Builder invBuilder = Mockito.mock(Invocation.Builder.class); |
| 24 | + Response response = Mockito.mock(Response.class); |
| 25 | + |
| 26 | + Mockito.when( |
| 27 | + webTarget.path(Mockito.anyString())).thenReturn( |
| 28 | + webTarget); |
| 29 | + Mockito.when( |
| 30 | + webTarget.request()).thenReturn( |
| 31 | + invBuilder); |
| 32 | + |
| 33 | + Mockito.when( |
| 34 | + invBuilder.get()).thenReturn( |
| 35 | + response); |
| 36 | + Mockito.when( |
| 37 | + invBuilder.delete()).thenReturn( |
| 38 | + response); |
| 39 | + Mockito.when( |
| 40 | + invBuilder.post(Mockito.any(Entity.class))).thenReturn( |
| 41 | + response); |
| 42 | + |
| 43 | + return webTarget; |
| 44 | + |
| 45 | + } |
| 46 | + |
| 47 | + @Before |
| 48 | + public void prepare() { |
| 49 | + webTarget = mockedWebTarget(); |
| 50 | + config = new GeoServerConfig(); |
| 51 | + client = new GeoServerRestClient( |
| 52 | + config, |
| 53 | + webTarget); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void testGetFeatureLayer() { |
| 58 | + client.getFeatureLayer("some_layer"); |
| 59 | + Mockito.verify( |
| 60 | + webTarget).path( |
| 61 | + "rest/layers/some_layer.json"); |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + public void testGetConfig() { |
| 66 | + GeoServerConfig returnedConfig = client.getConfig(); |
| 67 | + Assert.assertEquals( |
| 68 | + config, |
| 69 | + returnedConfig); |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + public void testGetCoverage() { |
| 74 | + client.getCoverage( |
| 75 | + "some_workspace", |
| 76 | + "some_cvgStore", |
| 77 | + "some_coverage"); |
| 78 | + Mockito.verify( |
| 79 | + webTarget).path( |
| 80 | + "rest/workspaces/some_workspace/coveragestores/some_cvgStore/coverages/some_coverage.json"); |
| 81 | + } |
| 82 | + |
| 83 | + @Test |
| 84 | + public void testGetCoverageStores() { |
| 85 | + client.getCoverageStores("some_workspace"); |
| 86 | + Mockito.verify( |
| 87 | + webTarget).path( |
| 88 | + "rest/workspaces/some_workspace/coveragestores.json"); |
| 89 | + } |
| 90 | + |
| 91 | + @Test |
| 92 | + public void testGetCoverages() { |
| 93 | + client.getCoverages( |
| 94 | + "some_workspace", |
| 95 | + "some_cvgStore"); |
| 96 | + Mockito.verify( |
| 97 | + webTarget).path( |
| 98 | + "rest/workspaces/some_workspace/coveragestores/some_cvgStore/coverages.json"); |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + public void testGetDatastore() { |
| 103 | + client.getDatastore( |
| 104 | + "some_workspace", |
| 105 | + "some_datastore"); |
| 106 | + Mockito.verify( |
| 107 | + webTarget).path( |
| 108 | + "rest/workspaces/some_workspace/datastores/some_datastore.json"); |
| 109 | + } |
| 110 | + |
| 111 | + @Test |
| 112 | + public void testGetStyle() { |
| 113 | + client.getStyle("some_style"); |
| 114 | + Mockito.verify( |
| 115 | + webTarget).path( |
| 116 | + "rest/styles/some_style.sld"); |
| 117 | + } |
| 118 | + |
| 119 | + @Test |
| 120 | + public void testGetStyles() { |
| 121 | + client.getStyles(); |
| 122 | + Mockito.verify( |
| 123 | + webTarget).path( |
| 124 | + "rest/styles.json"); |
| 125 | + } |
| 126 | + |
| 127 | + @Test |
| 128 | + public void testGetWorkspaces() { |
| 129 | + client.getWorkspaces(); |
| 130 | + Mockito.verify( |
| 131 | + webTarget).path( |
| 132 | + "rest/workspaces.json"); |
| 133 | + } |
| 134 | + |
| 135 | + @Test |
| 136 | + public void addFeatureLayer() { |
| 137 | + client.addFeatureLayer( |
| 138 | + "some_workspace", |
| 139 | + "some_datastore", |
| 140 | + "some_layer", |
| 141 | + "some_style"); |
| 142 | + Mockito.verify( |
| 143 | + webTarget).path( |
| 144 | + "rest/layers/some_layer.json"); |
| 145 | + } |
| 146 | + |
| 147 | + @Test |
| 148 | + public void addCoverage() { |
| 149 | + client.addCoverage( |
| 150 | + "some_workspace", |
| 151 | + "some_cvgStore", |
| 152 | + "some_coverage"); |
| 153 | + Mockito.verify( |
| 154 | + webTarget).path( |
| 155 | + "rest/workspaces/some_workspace/coveragestores/some_cvgStore/coverages"); |
| 156 | + } |
| 157 | + |
| 158 | + @Test |
| 159 | + public void addWorkspace() { |
| 160 | + client.addWorkspace("some_workspace"); |
| 161 | + Mockito.verify( |
| 162 | + webTarget).path( |
| 163 | + "rest/workspaces"); |
| 164 | + } |
| 165 | +} |
0 commit comments