/*
 * Copyright 2000-2015 JetBrains s.r.o.
 *
 * 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.
 */

package jetbrains.buildServer.clouds.vmware.vmrun.remote;

import com.thoughtworks.xstream.XStream;
import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
import jetbrains.buildServer.clouds.vmware.settings.VMImageInfo;
import jetbrains.buildServer.messages.XStreamHolder;
import junit.framework.Assert;
import org.testng.annotations.Test;

/**
 * @author Eugene Petrenko (eugene.petrenko@gmail.com)
 *         Date: 02.07.12 20:57
 */
public class XStreamSerializationTest {
  @Test
  public void test_VMImageInfo() throws UnsupportedEncodingException {
    final XStream xs = new XStreamHolder().getXStream(getClass().getClassLoader());
    String xml = "<jetbrains.buildServer.clouds.vmware.settings.VMImageInfo>\n" +
                 "  <!-- virtual machine unique id -->\n" +
                 "  <myId>Win7-64.Professional.SP1</myId>\n" +
                 "\n" +
                 "  <!-- local path to .vmx file -->\n" +
                 "  <myImagePath>C:\\VMWare\\Windows 7 x64 Professional SP1\\Clone of Windows 7 x64 Professional No SP.vmx</myImagePath>\n" +
                 "    \n" +
                 "  <!-- path to buildAgent.properties inside the virtual machine -->\n" +
                 "  <myImageAgentConfigLocation>C:\\BuildAgent\\conf\\buildAgent.properties</myImageAgentConfigLocation>\n" +
                 "  \n" +
                 "  <!-- login/password for the virtual machine administrator account -->\n" +
                 "  <myUserName>DOMAIN\\USERNAME</myUserName>\n" +
                 "  <myPassword>PWD</myPassword>\n" +
                 "</jetbrains.buildServer.clouds.vmware.settings.VMImageInfo>";
    byte[] data = xml.getBytes("utf-8");
    VMImageInfo info = (VMImageInfo)xs.fromXML(new ByteArrayInputStream(data));

    System.out.println(info.getClass().getName());

    Assert.assertNotNull(info);
  }
}
