Skip to content

Commit a6b585a

Browse files
committed
Implementing Plugin configure() method
1 parent 4b735df commit a6b585a

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

src/main/java/com/amihaiemil/docker/Plugin.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434
* A docker plugin.
3535
* @author Boris Kuzmic ([email protected])
3636
* @see <a href="https://docs.docker.com/engine/api/v1.35/#tag/Plugin">Docker Plugin API</a>
37-
* @todo #266:30min Implement Plugin#configure method. The tests are already
38-
* coded, so after the implementation just remove the ignore annotation from
39-
* these tests. More information about Configure API method can be found at:
40-
* https://docs.docker.com/engine/api/v1.35/#operation/PluginSet
4137
* @since 0.0.7
4238
*/
4339
public interface Plugin extends JsonObject {

src/main/java/com/amihaiemil/docker/RtPlugin.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
import java.io.IOException;
2929
import java.net.URI;
3030
import java.util.Map;
31+
import javax.json.Json;
3132
import javax.json.JsonArray;
33+
import javax.json.JsonArrayBuilder;
3234
import javax.json.JsonObject;
3335
import org.apache.http.HttpStatus;
3436
import org.apache.http.client.HttpClient;
@@ -170,12 +172,31 @@ public void push() throws IOException, UnexpectedResponseException {
170172
@Override
171173
public void configure(final Map<String, String> options)
172174
throws IOException, UnexpectedResponseException {
173-
throw new UnsupportedOperationException(
174-
String.join(" ",
175-
"RtPlugin.configure() is not yet implemented.",
176-
"If you can contribute please",
177-
"do it here: https://www.github.com/amihaiemil/docker-java-api"
178-
)
179-
);
175+
final JsonArrayBuilder json = Json.createArrayBuilder();
176+
if (options != null) {
177+
options.forEach(
178+
(key, value) -> json.add(String.format("%s=%s", key, value))
179+
);
180+
}
181+
final HttpPost upgrade =
182+
new HttpPost(
183+
String.format("%s/%s", this.uri.toString(), "set")
184+
);
185+
try {
186+
upgrade.setEntity(
187+
new StringEntity(
188+
json.build().toString(), ContentType.APPLICATION_JSON
189+
)
190+
);
191+
this.client.execute(
192+
upgrade,
193+
new MatchStatus(
194+
upgrade.getURI(),
195+
HttpStatus.SC_NO_CONTENT
196+
)
197+
);
198+
} finally {
199+
upgrade.releaseConnection();
200+
}
180201
}
181202
}

src/test/java/com/amihaiemil/docker/RtPluginTestCase.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import org.hamcrest.MatcherAssert;
4444
import org.hamcrest.collection.IsCollectionWithSize;
4545
import org.hamcrest.core.IsEqual;
46-
import org.junit.Ignore;
4746
import org.junit.Test;
4847
import org.mockito.Mockito;
4948

@@ -442,7 +441,6 @@ public void pushFailsPluginNotInstalled() throws Exception {
442441
* RtPlugin configure plugin.
443442
* @throws Exception If something goes wrong.
444443
*/
445-
@Ignore
446444
@Test
447445
public void configureOk() throws Exception {
448446
new ListedPlugins(
@@ -496,7 +494,6 @@ public void configureOk() throws Exception {
496494
* responds with 404.
497495
* @throws Exception If something goes wrong.
498496
*/
499-
@Ignore
500497
@Test(expected = UnexpectedResponseException.class)
501498
public void configureFailsPluginNotInstalled() throws Exception {
502499
final Plugin plugin = new RtPlugin(

0 commit comments

Comments
 (0)