Skip to content

Commit ca0c2bf

Browse files
committed
Merge branch '__rultor'
2 parents 2e711aa + a6b585a commit ca0c2bf

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
@@ -40,7 +40,6 @@
4040
import org.hamcrest.MatcherAssert;
4141
import org.hamcrest.collection.IsCollectionWithSize;
4242
import org.hamcrest.core.IsEqual;
43-
import org.junit.Ignore;
4443
import org.junit.Test;
4544
import org.mockito.Mockito;
4645

@@ -437,7 +436,6 @@ public void pushFailsPluginNotInstalled() throws Exception {
437436
* RtPlugin configure plugin.
438437
* @throws Exception If something goes wrong.
439438
*/
440-
@Ignore
441439
@Test
442440
public void configureOk() throws Exception {
443441
new ListedPlugins(
@@ -493,7 +491,6 @@ public void configureOk() throws Exception {
493491
* responds with 404.
494492
* @throws Exception If something goes wrong.
495493
*/
496-
@Ignore
497494
@Test(expected = UnexpectedResponseException.class)
498495
public void configureFailsPluginNotInstalled() throws Exception {
499496
final Plugin plugin = new RtPlugin(

0 commit comments

Comments
 (0)