Search in sources :

Example 1 with METADATA

use of ml.comet.experiment.impl.constants.FormParamName.METADATA in project comet-java-sdk by comet-ml.

the class ConnectionUtilsTest method testCreatePostFormRequest.

@Test
public void testCreatePostFormRequest() {
    // Create test data
    // 
    String url = "http://test.com" + ApiEndpoints.ADD_ASSET;
    Map<QueryParamName, String> params = new HashMap<QueryParamName, String>() {

        {
            put(EXPERIMENT_KEY, "someValue");
            put(OVERWRITE, Boolean.toString(true));
        }
    };
    Map<FormParamName, Object> formParams = new HashMap<FormParamName, Object>() {

        {
            put(METADATA, "some string");
            put(LINK, "https://some.site.com");
        }
    };
    // Create request
    // 
    Request r = ConnectionUtils.createPostFormRequest(url, params, formParams);
    this.validateRequest(r, url, params, POST, MULTIPART_FORM_DATA.toString());
    // Check body parts
    // 
    assertEquals(2, r.getBodyParts().size(), "wrong number of body parts");
    assertTrue(r.getBodyParts().stream().map(part -> (StringPart) part).allMatch(stringPart -> Objects.equals(stringPart.getValue(), formParams.get(FormParamName.valueOf(stringPart.getName().toUpperCase())))));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) OVERWRITE(ml.comet.experiment.impl.constants.QueryParamName.OVERWRITE) Request(org.asynchttpclient.Request) HashMap(java.util.HashMap) TEXT_PLAIN(io.netty.handler.codec.http.HttpHeaderValues.TEXT_PLAIN) EXPERIMENT_KEY(ml.comet.experiment.impl.constants.QueryParamName.EXPERIMENT_KEY) ApiEndpoints(ml.comet.experiment.impl.constants.ApiEndpoints) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) URI(java.net.URI) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) LINK(ml.comet.experiment.impl.constants.FormParamName.LINK) FormParamName(ml.comet.experiment.impl.constants.FormParamName) ValueSource(org.junit.jupiter.params.provider.ValueSource) FILE(ml.comet.experiment.impl.constants.FormParamName.FILE) QueryParamName(ml.comet.experiment.impl.constants.QueryParamName) POST(org.asynchttpclient.util.HttpConstants.Methods.POST) MULTIPART_FORM_DATA(io.netty.handler.codec.http.HttpHeaderValues.MULTIPART_FORM_DATA) ByteArrayPart(org.asynchttpclient.request.body.multipart.ByteArrayPart) FilePart(org.asynchttpclient.request.body.multipart.FilePart) HtmlRest(ml.comet.experiment.impl.rest.HtmlRest) File(java.io.File) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) APPLICATION_JSON(io.netty.handler.codec.http.HttpHeaderValues.APPLICATION_JSON) JsonUtils(ml.comet.experiment.impl.utils.JsonUtils) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TestUtils(ml.comet.experiment.impl.TestUtils) HttpConstants(org.asynchttpclient.util.HttpConstants) METADATA(ml.comet.experiment.impl.constants.FormParamName.METADATA) StringPart(org.asynchttpclient.request.body.multipart.StringPart) CONTENT_TYPE(io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE) APPLICATION_OCTET_STREAM(io.netty.handler.codec.http.HttpHeaderValues.APPLICATION_OCTET_STREAM) HashMap(java.util.HashMap) Request(org.asynchttpclient.Request) QueryParamName(ml.comet.experiment.impl.constants.QueryParamName) FormParamName(ml.comet.experiment.impl.constants.FormParamName) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

CONTENT_TYPE (io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE)1 APPLICATION_JSON (io.netty.handler.codec.http.HttpHeaderValues.APPLICATION_JSON)1 APPLICATION_OCTET_STREAM (io.netty.handler.codec.http.HttpHeaderValues.APPLICATION_OCTET_STREAM)1 MULTIPART_FORM_DATA (io.netty.handler.codec.http.HttpHeaderValues.MULTIPART_FORM_DATA)1 TEXT_PLAIN (io.netty.handler.codec.http.HttpHeaderValues.TEXT_PLAIN)1 File (java.io.File)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Objects (java.util.Objects)1 TestUtils (ml.comet.experiment.impl.TestUtils)1 ApiEndpoints (ml.comet.experiment.impl.constants.ApiEndpoints)1 FormParamName (ml.comet.experiment.impl.constants.FormParamName)1 FILE (ml.comet.experiment.impl.constants.FormParamName.FILE)1 LINK (ml.comet.experiment.impl.constants.FormParamName.LINK)1 METADATA (ml.comet.experiment.impl.constants.FormParamName.METADATA)1 QueryParamName (ml.comet.experiment.impl.constants.QueryParamName)1 EXPERIMENT_KEY (ml.comet.experiment.impl.constants.QueryParamName.EXPERIMENT_KEY)1 OVERWRITE (ml.comet.experiment.impl.constants.QueryParamName.OVERWRITE)1 HtmlRest (ml.comet.experiment.impl.rest.HtmlRest)1