package eu.chargetime.ocpp.feature.profile.test;

import eu.chargetime.ocpp.feature.Feature;
import eu.chargetime.ocpp.feature.SetChargingProfileFeature;
import eu.chargetime.ocpp.feature.profile.ServerSmartChargingProfile;
import eu.chargetime.ocpp.model.core.ChargingProfile;
import eu.chargetime.ocpp.model.core.ChargingProfileKindType;
import eu.chargetime.ocpp.model.core.ChargingProfilePurposeType;
import eu.chargetime.ocpp.model.core.ChargingRateUnitType;
import eu.chargetime.ocpp.model.core.ChargingSchedule;
import eu.chargetime.ocpp.model.core.ChargingSchedulePeriod;
import eu.chargetime.ocpp.model.smartcharging.SetChargingProfileRequest;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

/*
 * ChargeTime.eu - Java-OCA-OCPP
 *
 * MIT License
 *
 * Copyright (C) 2017 Emil Christopher Solli Melar <emil@iconsultable.no>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

@RunWith(MockitoJUnitRunner.class)
public class ServerSmartChargingProfileTest extends ProfileTest {

    private ServerSmartChargingProfile smartCharging;

    @Before
    public void setup() {
        smartCharging = new ServerSmartChargingProfile();
    }

    @Test
    public void getFeatureList_containsSetChargingProfileFeature() {
        // When
        Feature[] features = smartCharging.getFeatureList();

        // Then
        assertThat(findFeature(features, "SetChargingProfile"), is(instanceOf(SetChargingProfileFeature.class)));
    }

    @Test
    public void createSetChargingProfileRequest_returnsValidSetChargingProfileRequest() {

        int connectorId = 123;

        ChargingProfile profile = new ChargingProfile();

        int profileId = 666;
        profile.setChargingProfileId(profileId);
        profile.setChargingProfilePurpose(ChargingProfilePurposeType.TxProfile);
        profile.setStackLevel(42);
        profile.setChargingProfileKind(ChargingProfileKindType.Absolute);

        ChargingSchedule schedule = new ChargingSchedule();
        schedule.setChargingRateUnit(ChargingRateUnitType.A);
        ChargingSchedulePeriod period = new ChargingSchedulePeriod();
        period.setStartPeriod(0);
        period.setLimit(20.3);
        period.setNumberPhases(1);
        schedule.setChargingSchedulePeriod(new ChargingSchedulePeriod[]{period});
        profile.setChargingSchedule(schedule);

        // When
        SetChargingProfileRequest result = smartCharging.createSetChargingProfileRequest(connectorId, profile);

        // Then
        assertThat(result.validate(), is(true));
        assertThat(result.getConnectorId(), is(connectorId));

        ChargingProfile resultProfile = result.getCsChargingProfiles();
        assertThat(profile, is(resultProfile));

    }

}

@@ -43,16 +43,79 @@
 .test;%0A%0A
+import eu.chargetime.ocpp.feature.ClearChargingProfileFeature;%0A
 import e
@@ -141,32 +141,32 @@
 eature.Feature;%0A
-
 import eu.charge
@@ -317,31 +317,17 @@
 el.core.
-ChargingProfile
+*
 ;%0Aimport
@@ -356,276 +356,49 @@
 del.
-core.ChargingProfileKindType;%0Aimport eu.chargetime.ocpp.model.core.ChargingProfilePurposeType;%0Aimport eu.chargetime.ocpp.model.core.ChargingRateUnitType;%0Aimport eu.chargetime.ocpp.model.core.ChargingSchedule;%0Aimport eu.chargetime.ocpp.model.core.ChargingSchedulePeriod
+smartcharging.ClearChargingProfileRequest
 ;%0Aim
@@ -3769,10 +3769,578 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void getFeatureList_containsClearChargingProfileFeature() %7B%0A        // When%0A        Feature%5B%5D features = smartCharging.getFeatureList();%0A%0A        // Then%0A        assertThat(findFeature(features, %22ClearChargingProfile%22), is(instanceOf(ClearChargingProfileFeature.class)));%0A    %7D%0A%0A    @Test%0A    public void createClearCacheRequest_returnsValidClearCacheRequest() %7B%0A        // When%0A        ClearChargingProfileRequest result = smartCharging.createClearChargingProfileRequest();%0A%0A        // Then%0A        assertThat(result.validate(), is(true));%0A    %7D%0A
 %7D%0A

Implement unit test for clearChargingProfileRequest and confirmation