/*
 * Copyright 2014-2015 Groupon, Inc
 * Copyright 2014-2015 The Billing Project, LLC
 *
 * The Billing Project licenses this file to you 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.
 */

package org.killbill.billing.catalog.dao;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.joda.time.DateTime;
import org.killbill.billing.catalog.CatalogTestSuiteWithEmbeddedDB;
import org.killbill.billing.catalog.DefaultPlanPhasePriceOverride;
import org.killbill.billing.catalog.DefaultTierPriceOverride;
import org.killbill.billing.catalog.DefaultTieredBlockPriceOverride;
import org.killbill.billing.catalog.DefaultUsagePriceOverride;
import org.killbill.billing.catalog.StandaloneCatalog;
import org.killbill.billing.catalog.api.Currency;
import org.killbill.billing.catalog.api.Plan;
import org.killbill.billing.catalog.api.PlanPhasePriceOverride;
import org.killbill.billing.catalog.api.TierPriceOverride;
import org.killbill.billing.catalog.api.TieredBlockPriceOverride;
import org.killbill.billing.catalog.api.UsagePriceOverride;
import org.killbill.billing.catalog.api.UsageType;
import org.testng.Assert;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

public class TestCatalogUserApi extends CatalogTestSuiteWithEmbeddedDB {

    @Test(groups = "slow")
    public void testOverrideUploadCatalog() throws Exception {

        final StandaloneCatalog catalog = getCatalog("SpyCarBasic.xml");;
        final Plan plan = catalog.findPlan("standard-monthly");

        final PlanPhasePriceOverride[] resolvedOverrides = new PlanPhasePriceOverride[plan.getAllPhases().length];
        resolvedOverrides[0] = null;
        resolvedOverrides[1] = new DefaultPlanPhasePriceOverride(plan.getFinalPhase().getName(), Currency.USD, null, new BigDecimal("128.76"), null);
        final CatalogOverridePlanDefinitionModelDao newPlan = catalogOverrideDao.getOrCreateOverridePlanDefinition(plan, new DateTime(catalog.getEffectiveDate()), resolvedOverrides, internalCallContext);
        assertEquals(newPlan.getParentPlanName(), "standard-monthly");
        assertTrue(newPlan.getIsActive());
    }


}


@@ -817,30 +817,119 @@
 ort 
-org.joda.time.DateTime
+javax.inject.Inject;%0A%0Aimport org.joda.time.DateTime;%0Aimport org.killbill.billing.callcontext.MutableCallContext
 ;%0Aim
@@ -1310,16 +1310,72 @@
 atalog;%0A
+import org.killbill.billing.catalog.api.CatalogUserApi;%0A
 import o
@@ -1821,24 +1821,104 @@
 ions.Test;%0A%0A
+import com.google.common.base.Charsets;%0Aimport com.google.common.io.Resources;%0A%0A
 import stati
@@ -2070,20 +2070,127 @@
 edDB %7B%0A%0A
+%09@Inject%0A%09protected CatalogUserApi catalogUserApi;%0A%09%0A%09@Inject%0A%09protected MutableCallContext callContext;%0A
     
+%0A%09
 @Test(gr
@@ -2340,17 +2340,203 @@
 c.xml%22);
-;
+%0A        %0A        catalogUserApi.uploadCatalog(Resources.asCharSource(Resources.getResource(%22org/killbill/billing/catalog/SpyCarBasic.xml%22), Charsets.UTF_8).read(), callContext);%0A        
 %0A       

Update TestCatalogUserApi.java