<commit_before>/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.jboss.jca.test.core.mdr.unit;

import org.jboss.jca.core.api.MetaDataRepository;

import java.net.URL;

import org.jboss.ejb3.test.mc.bootstrap.EmbeddedTestMcBootstrap;
import org.jboss.logging.Logger;
import org.jboss.metadata.rar.jboss.RARDeploymentMetaData;
import org.jboss.metadata.rar.jboss.mcf.ManagedConnectionFactoryDeploymentGroup;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import static org.junit.Assert.*;

/**
 * MetaDataRepositoryTestCase.
 * 
 * Tests for the JBoss specific metadata repository functionality.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Revision: $
 */
public class MetaDataRepositoryTestCase
{

   // --------------------------------------------------------------------------------||
   // Class Members ------------------------------------------------------------------||
   // --------------------------------------------------------------------------------||

   private static Logger log = Logger.getLogger(MetaDataRepositoryTestCase.class);

   /*
    * Bootstrap (MC Facade)
    */
   private static EmbeddedTestMcBootstrap bootstrap;

   // --------------------------------------------------------------------------------||
   // Tests --------------------------------------------------------------------------||
   // --------------------------------------------------------------------------------||

   /**
    * Test that the MetaDataRepository is defined in the MC
    * @throws Throwable throwable exception 
    */
   @Test
   public void testDefined() throws Throwable
   {
      MetaDataRepository mdr =
         bootstrap.lookup("MetaDataRepository", MetaDataRepository.class);

      assertNotNull(mdr);
   }

   /**
    * Test null name for addRARDeploymentMetaData
    * @throws Throwable throwable exception 
    */
   @Test
   public void testAddRARDeploymentMetaDataNullName() throws Throwable
   {
      MetaDataRepository mdr =
         bootstrap.lookup("MetaDataRepository", MetaDataRepository.class);

      assertNotNull(mdr);

      try
      {
         RARDeploymentMetaData rdmd = mdr.addRARDeploymentMetaData(null, null);
         fail("Null name");
      }
      catch (Throwable t)
      {
         // Expected
      }
   }

   /**
    * Test null rdmd for addRARDeploymentMetaData
    * @throws Throwable throwable exception 
    */
   @Test
   public void testAddRARDeploymentMetaDataNullRDMD() throws Throwable
   {
      MetaDataRepository mdr =
         bootstrap.lookup("MetaDataRepository", MetaDataRepository.class);

      assertNotNull(mdr);

      try
      {
         RARDeploymentMetaData rdmd = mdr.addRARDeploymentMetaData("test", null);
         fail("Null rdmd");
      }
      catch (Throwable t)
      {
         // Expected
      }
   }

   /**
    * Test for addRARDeploymentMetaData
    * @throws Throwable throwable exception 
    */
   @Test
   public void testAddRARDeploymentMetaData() throws Throwable
   {
      MetaDataRepository mdr =
         bootstrap.lookup("MetaDataRepository", MetaDataRepository.class);

      assertNotNull(mdr);

      RARDeploymentMetaData rdmd = new RARDeploymentMetaData();
      rdmd = mdr.addRARDeploymentMetaData("test", rdmd);

      mdr.removeRARDeploymentMetaData("test");
   }

   /**
    * Test null name for getRARDeploymentMetaData
    * @throws Throwable throwable exception 
    */
   @Test
   public void testGetRARDeploymentMetaDataNullName() throws Throwable
   {
      MetaDataRepository mdr =
         bootstrap.lookup("MetaDataRepository", MetaDataRepository.class);

      assertNotNull(mdr);

      try
      {
         RARDeploymentMetaData rdmd = mdr.getRARDeploymentMetaData(null);
         fail("Null name");
      }
      catch (Throwable t)
      {
         // Expected
      }
   }

   /**
    * Test undefined name for getRARDeploymentMetaData
    * @throws Throwable throwable exception 
    */
   @Test
   public void testGetRARDeploymentMetaDataUndefinedName() throws Throwable
   {
      MetaDataRepository mdr =
         bootstrap.lookup("MetaDataRepository", MetaDataRepository.class);

      assertNotNull(mdr);

      RARDeploymentMetaData rdmd = mdr.getRARDeploymentMetaData("test");
      assertNull(rdmd);
   }

   /**
    * Test for getRARDeploymentMetaData
    * @throws Throwable throwable exception 
    */
   @Test
   public void testGetRARDeploymentMetaData() throws Throwable
   {
      MetaDataRepository mdr =
         bootstrap.lookup("MetaDataRepository", MetaDataRepository.class);

      assertNotNull(mdr);

      RARDeploymentMetaData rdmd1 = new RARDeploymentMetaData();
      mdr.addRARDeploymentMetaData("test", rdmd1);

      RARDeploymentMetaData rdmd2 = mdr.getRARDeploymentMetaData("test");
      assertNotNull(rdmd2);

      assertEquals("Objects are not the same", rdmd1, rdmd2);

      mdr.removeRARDeploymentMetaData("test");
   }

   /**
    * Test null name for removeRARDeploymentMetaData
    * @throws Throwable throwable exception 
    */
   @Test
   public void testRemoveRARDeploymentMetaDataNullName() throws Throwable
   {
      MetaDataRepository mdr =
         bootstrap.lookup("MetaDataRepository", MetaDataRepository.class);

      assertNotNull(mdr);

      try
      {
         boolean result = mdr.removeRARDeploymentMetaData(null);
         fail("Null name");
      }
      catch (Throwable t)
      {
         // Expected
      }
   }

   /**
    * Test undefined name for removeRARDeploymentMetaData
    * @throws Throwable throwable exception 
    */
   @Test
   public void testRemoveRARDeploymentMetaDataUndefinedName() throws Throwable
   {
      MetaDataRepository mdr =<commit_msg>[JBJCA-6] add testMultiAddGetRARDeploymentMetaData<commit_after>/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.jboss.jca.test.core.mdr.unit;

import org.jboss.jca.core.api.MetaDataRepository;

import java.net.URL;

import org.jboss.ejb3.test.mc.bootstrap.EmbeddedTestMcBootstrap;
import org.jboss.logging.Logger;
import org.jboss.metadata.rar.jboss.RARDeploymentMetaData;
import org.jboss.metadata.rar.jboss.mcf.ManagedConnectionFactoryDeploymentGroup;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import static org.junit.Assert.*;

/**
 * MetaDataRepositoryTestCase.
 * 
 * Tests for the JBoss specific metadata repository functionality.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Revision: $
 */
public class MetaDataRepositoryTestCase
{

   // --------------------------------------------------------------------------------||
   // Class Members ------------------------------------------------------------------||
   // --------------------------------------------------------------------------------||

   private static Logger log = Logger.getLogger(MetaDataRepositoryTestCase.class);

   /*
    * Bootstrap (MC Facade)
    */
   private static EmbeddedTestMcBootstrap bootstrap;

   // --------------------------------------------------------------------------------||
   // Tests --------------------------------------------------------------------------||
   // --------------------------------------------------------------------------------||

   /**
    * Test that the MetaDataRepository is defined in the MC
    * @throws Throwable throwable exception 
    */
   @Test
   public void testDefined() throws Throwable
   {
      MetaDataRepository mdr =
         bootstrap.lookup("MetaDataRepository", MetaDataRepository.class);

      assertNotNull(mdr);
   }

   /**
    * Test null name for addRARDeploymentMetaData
    * @throws Throwable throwable exception 
    */
   @Test
   public void testAddRARDeploymentMetaDataNullName() throws Throwable
   {
      MetaDataRepository mdr =
         bootstrap.lookup("MetaDataRepository", MetaDataRepository.class);

      assertNotNull(mdr);

      try
      {
         RARDeploymentMetaData rdmd = mdr.addRARDeploymentMetaData(null, null);
         fail("Null name");
      }
      catch (Throwable t)
      {
         // Expected
      }
   }

   /**
    * Test null rdmd for addRARDeploymentMetaData
    * @throws Throwable throwable exception 
    */
   @Test
   public void testAddRARDeploymentMetaDataNullRDMD() throws Throwable
   {
      MetaDataRepository mdr =
         bootstrap.lookup("MetaDataRepository", MetaDataRepository.class);

      assertNotNull(mdr);

      try
      {
         RARDeploymentMetaData rdmd = mdr.addRARDeploymentMetaData("test", null);
         fail("Null rdmd");
      }
      catch (Throwable t)
      {
         // Expected
      }
   }

   /**
    * Test for addRARDeploymentMetaData
    * @throws Throwable throwable exception 
    */
   @Test
   public void testAddRARDeploymentMetaData() throws Throwable
   {
      MetaDataRepository mdr =
         bootstrap.lookup("MetaDataRepository", MetaDataRepository.class);

      assertNotNull(mdr);

      RARDeploymentMetaData rdmd = new RARDeploymentMetaData();
      rdmd = mdr.addRARDeploymentMetaData("test", rdmd);

      mdr.removeRARDeploymentMetaData("test");
   }

   /**
    * Test null name for getRARDeploymentMetaData
    * @throws Throwable throwable exception 
    */
   @Test
   public void testGetRARDeploymentMetaDataNullName() throws Throwable
   {
      MetaDataRepository mdr =
         bootstrap.lookup("MetaDataRepository", MetaDataRepository.class);

      assertNotNull(mdr);

      try
      {
         RARDeploymentMetaData rdmd = mdr.getRARDeploymentMetaData(null);
         fail("Null name");
      }
      catch (Throwable t)
      {
         // Expected
      }
   }

   /**
    * Test undefined name for getRARDeploymentMetaData
    * @throws Throwable throwable exception 
    */
   @Test
   public void testGetRARDeploymentMetaDataUndefinedName() throws Throwable
   {
      MetaDataRepository mdr =
         bootstrap.lookup("MetaDataRepository", MetaDataRepository.class);

      assertNotNull(mdr);

      RARDeploymentMetaData rdmd = mdr.getRARDeploymentMetaData("test");
      assertNull(rdmd);
   }

   /**
    * Test for getRARDeploymentMetaData
    * @throws Throwable throwable exception 
    */
   @Test
   public void testGetRARDeploymentMetaData() throws Throwable
   {
      MetaDataRepository mdr =
         bootstrap.lookup("MetaDataRepository", MetaDataRepository.class);

      assertNotNull(mdr);

      RARDeploymentMetaData rdmd1 = new RARDeploymentMetaData();
      mdr.addRARDeploymentMetaData("test", rdmd1);

      RARDeploymentMetaData rdmd2 = mdr.getRARDeploymentMetaData("test");
      assertNotNull(rdmd2);

      assertEquals("Objects are not the same", rdmd1, rdmd2);

      mdr.removeRARDeploymentMetaData("test");
   }


   /**
    * Test for getRARDeploymentMetaData
    * @throws Throwable throwable exception 
    */
   @Test
   public void testMultiAddGetRARDeploymentMetaData() throws Throwable
   {
      MetaDataRepository mdr =
         bootstrap.lookup("MetaDataRepository", MetaDataRepository.class);

      assertNotNull(mdr);

      RARDeploymentMetaData rdmd11 = new RARDeploymentMetaData();
      mdr.addRARDeploymentMetaData("test1", rdmd11);

      RARDeploymentMetaData rdmd21 = new RARDeploymentMetaData();
      mdr.addRARDeploymentMetaData("test2", rdmd21);
      
      RARDeploymentMetaData rdmd12 = mdr.getRARDeploymentMetaData("test1");
      assertNotNull(rdmd12);
      
      RARDeploymentMetaData rdmd22 = mdr.getRARDeploymentMetaData("test2");
      assertNotNull(rdmd22);

      assertEquals("Objects are not the same", rdmd11, rdmd12);
      assertEquals("Objects are not the same", rdmd21, rdmd22);

      mdr.removeRARDeploymentMetaData("test1");
      mdr.removeRARDeploymentMetaData("test2");
   }
   
   /**
    * Test null name for removeRARDeploymentMetaData
    * @throws Throwable throwable exception 
    */
   @Test
   public void testRemoveRARDeploymentMetaDataNullName() throws Throwable
   {
      MetaDataRepository mdr =
         bootstrap.lookup("MetaDataRepository", MetaDataRepository.class);

      assertNotNull(mdr);

      try
      {
         boolean result = mdr.removeRARDeploymentMetaData(null);
         fail("Null name");
      }
      catch (Throwable t)
      {
         // Expected
      }
   }

   /**
    * Test undefined name for removeRARDeploymentMetaData
    * @throws Throwable throwable exception 
    */
   @Test
   public void testRemoveRARDeploymentMetaDataUndefinedName() throws Throwable
   {
      MetaDataRepository mdr =
{'fraction_non_alphanumeric': 0.14441379310344826, 'fraction_numerical': 0.006, 'mean_word_length': 2.3770377270610155, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6081761', 'n_tokens_mistral': 3973, 'n_tokens_neox': 3860, 'n_words': 978}