package client;

/*
 * Copyright (c) 2009-2019. Authors: see NOTICE file.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import be.cytomine.client.CytomineException;
import be.cytomine.client.collections.Collection;
import be.cytomine.client.models.Description;
import be.cytomine.client.models.Project;
import org.apache.log4j.Logger;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class DescriptionTests {

    private static final Logger log = Logger.getLogger(DescriptionTests.class);

    @BeforeAll
    static void init() throws CytomineException {
        Utils.connect();
    }

    @Test
    void testCreateDescription() throws CytomineException {
        log.info("test create description");
        Project project = Utils.getProject();
        String description = Utils.getRandomString();
        Description d = new Description(project, description).save();
        assertEquals(description, d.get("data"), "fetched data not the same used for the description creation");

        d = new Description().fetch(project);
        assertEquals(description, d.get("data"), "fetched data not the same used for the description creation");

        d.set("data", description+"bis");
        d.update();
        assertEquals(description+"bis", d.get("data"), "Not the data used for the description update");

        d.delete();
        try {
            new Description().fetch(project);
            assert false;
        } catch (CytomineException e) {
            assertEquals(404, e.getHttpCode());
        }
    }

    @Test
    void testCreateDescriptionIncorrect() throws CytomineException {
        log.info("test create incorrect description");

        try{
            new Description().save();
        } catch (CytomineException e){
            //TODO must be 404
            assertEquals(e.getHttpCode(), 500);
        }
    }

    @Test
    void testListDescription() throws CytomineException {
        log.info("test list description");
        Collection<Description> c = Collection.fetch(Description.class);

        log.info(c.size());
    }
}

@@ -759,27 +759,120 @@
 .models.
-Description
+Annotation;%0Aimport be.cytomine.client.models.Description;%0Aimport be.cytomine.client.models.ImageInstance
 ;%0Aimport
@@ -2765,10 +2765,1103 @@
 ;%0A    %7D%0A
+%0A    @Test%0A    void testGetDescriptionOfADomain() throws CytomineException %7B%0A        log.info(%22test get description by its associated domain%22);%0A        String description = Utils.getRandomString();%0A        Description d;%0A%0A        //project%0A        Project project = Utils.getNewProject();%0A        new Description(project, description).save();%0A        d = new Description().fetch(project);%0A        assertEquals(description, d.get(%22data%22), %22fetched data not the same used for the description creation%22);%0A%0A        //image%0A        ImageInstance image = Utils.getNewImageInstance();%0A        new Description(image, description).save();%0A        d = new Description().fetch(image);%0A        assertEquals(description, d.get(%22data%22), %22fetched data not the same used for the description creation%22);%0A%0A        //annotation%0A        Annotation annotation = Utils.getNewAnnotation();%0A        new Description(annotation, description).save();%0A        d = new Description().fetch(annotation);%0A        assertEquals(description, d.get(%22data%22), %22fetched data not the same used for the description creation%22);%0A    %7D%0A%0A
 %7D%0A

improve Description tests