/*
 * Copyright 2020-2020 Equinix, Inc
 * Copyright 2014-2020 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.beatrix.integration;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import java.io.IOException;

import org.joda.time.DateTime;
import org.killbill.billing.ErrorCode;
import org.killbill.billing.account.api.Account;
import org.killbill.billing.catalog.api.CatalogApiException;
import org.killbill.billing.util.callcontext.CallContext;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.google.common.base.Charsets;
import com.google.common.io.Resources;

public class TestCatalogValidation extends TestIntegrationBase {

    private CallContext testCallContext;
    private Account account;

    @BeforeMethod(groups = "slow")
    public void beforeMethod() throws Exception {
        if (hasFailed()) {
            return;
        }

        super.beforeMethod();

        // Setup tenant
        clock.setTime(new DateTime("2021-10-24T12:56:02"));
        testCallContext = setupTenant();

        // Setup account in right tenant
        account = setupAccount(testCallContext);
    }

    @Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/1481")
    public void testUploadCatalog() throws Exception {
        uploadCatalog("CatalogValidation-v1.xml");
        assertListenerStatus();
        try {
            uploadCatalog("CatalogValidation-v2.xml");
            assertListenerStatus();
    	} catch (CatalogApiException cApiException) {
    		assertEquals(cApiException.getCode(), ErrorCode.CAT_INVALID_FOR_TENANT.getCode());
    	}
    }
    
    @Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/1465")
    public void testUploadCatalogPlanValidation() throws Exception {
	try {
	    uploadCatalog("CatalogValidation-v2.xml");
	    assertListenerStatus();
	} catch (CatalogApiException cApiException) {
		assertEquals(cApiException.getCode(), ErrorCode.CAT_INVALID_FOR_TENANT.getCode());
	}

	try {
	    uploadCatalog("CatalogValidation-v3.xml");
	    assertListenerStatus();
	} catch (CatalogApiException cApiException) {
		//assertEquals(cApiException.getCode(), ErrorCode.CAT_INVALID_FOR_TENANT.getCode());
		assertNotEquals(cApiException.getCode(), ErrorCode.CAT_INVALID_FOR_TENANT.getCode());
	}

    }
    private void uploadCatalog(final String name) throws CatalogApiException, IOException {
        catalogUserApi.uploadCatalog(Resources.asCharSource(Resources.getResource("catalogs/testCatalogValidation/" + name), Charsets.UTF_8).read(), testCallContext);
    }
    

}

@@ -2446,16 +2446,270 @@
 ption %7B%0A
+%09/*%0A%09* This is the test case for #1465. CatalogValidation-v3.xml is added to the DB even if the validation fails for 1465. So to test this #1465 validation, 2nd catalog CatalogValidation-v4.xml needs to be updated and it validates those validations.%0A%09*/%0A
 %09try %7B%0A%09
@@ -2738,33 +2738,33 @@
 alogValidation-v
-2
+3
 .xml%22);%0A%09    ass
@@ -2958,33 +2958,33 @@
 alogValidation-v
-3
+4
 .xml%22);%0A%09    ass
@@ -3053,18 +3053,16 @@
 on) %7B%0A%09%09
-//
 assertEq
@@ -3140,96 +3140,8 @@
 ));%0A
-%09%09assertNotEquals(cApiException.getCode(), ErrorCode.CAT_INVALID_FOR_TENANT.getCode());%0A
 %09%7D%0A%0A

Update TestCatalogValidation.java