[CORD-2349] Correctly converting int32 to integer to allow migration of TOSCA recipes

Change-Id: Ifbe9bebc2ecb12accc67d5990fcb94fb03a8a1fb
diff --git a/lib/xos-genx/xos-genx-tests/test_tosca.py b/lib/xos-genx/xos-genx-tests/test_tosca.py
index 48a4db9..a771cbb 100644
--- a/lib/xos-genx/xos-genx-tests/test_tosca.py
+++ b/lib/xos-genx/xos-genx-tests/test_tosca.py
@@ -17,15 +17,49 @@
 from helpers import FakeArgs, XProtoTestHelpers
 
 
-class XProtoToscaTest(unittest.TestCase):
+class XProtoToscaTypeTest(unittest.TestCase):
 
     def setUp(self):
-        self.target = XProtoTestHelpers.write_tmp_target(
-"""
-{%- for m in proto.messages %}
-    {{ xproto_fields_to_tosca_keys(m.fields) }}
-{% endfor -%}
-""")
+        self.target_tosca_type = XProtoTestHelpers.write_tmp_target(
+            """
+            {%- for m in proto.messages %}
+            {% for f in m.fields %}
+                {{ xproto_tosca_field_type(f.type) }}
+            {% endfor -%}
+            {% endfor -%}
+            """)
+    def test_tosca_fields(self):
+        """
+        [XOS-GenX] should convert xproto types to tosca know types
+        """
+        xproto = \
+        """
+        option app_label = "test";
+
+        message Foo {
+            required string name = 1 [ null = "False", blank="False"];
+            required bool active = 1 [ null = "False", blank="False"];
+            required int32 quantity = 1 [ null = "False", blank="False"];
+        }
+        """
+
+        args = FakeArgs()
+        args.inputs = xproto
+        args.target = self.target_tosca_type
+        output = XOSGenerator.generate(args)
+        self.assertIn('string', output)
+        self.assertIn('boolean', output)
+        self.assertIn('integer', output)
+
+class XProtoToscaKeyTest(unittest.TestCase):
+
+    def setUp(self):
+        self.target_tosca_keys = XProtoTestHelpers.write_tmp_target(
+            """
+            {%- for m in proto.messages %}
+                {{ xproto_fields_to_tosca_keys(m.fields) }}
+            {% endfor -%}
+            """)
 
     def test_xproto_fields_to_tosca_keys_default(self):
         """
@@ -42,7 +76,7 @@
 
         args = FakeArgs()
         args.inputs = xproto
-        args.target = self.target
+        args.target = self.target_tosca_keys
         output = XOSGenerator.generate(args)
         self.assertIn('name', output)
 
@@ -63,7 +97,7 @@
 
         args = FakeArgs()
         args.inputs = xproto
-        args.target = self.target
+        args.target = self.target_tosca_keys
         output = XOSGenerator.generate(args)
         self.assertNotIn('name', output)
         self.assertIn('key_1', output)
@@ -85,7 +119,7 @@
 
         args = FakeArgs()
         args.inputs = xproto
-        args.target = self.target
+        args.target = self.target_tosca_keys
         output = XOSGenerator.generate(args)
         self.assertNotIn('name', output)
         self.assertIn('provider_service_instance_id', output)
\ No newline at end of file
diff --git a/lib/xos-genx/xosgenx/jinja2_extensions/base.py b/lib/xos-genx/xosgenx/jinja2_extensions/base.py
index d3982f1..0849ab9 100644
--- a/lib/xos-genx/xosgenx/jinja2_extensions/base.py
+++ b/lib/xos-genx/xosgenx/jinja2_extensions/base.py
@@ -239,21 +239,6 @@
 
     return options_str
 
-def xproto_tosca_required(null, blank, default=None):
-
-    if null == 'True' or blank == 'True' or default != 'False':
-        return "false"
-    return "true"
-
-def xproto_tosca_field_type(type):
-    """
-    TOSCA requires fields of type 'bool' to be 'boolean'
-    """
-    if type == "bool":
-        return "boolean"
-    else:
-        return type
-
 def xproto_type_to_swagger_type(f):
     try:
         content_type = f['options']['content_type']
diff --git a/lib/xos-genx/xosgenx/jinja2_extensions/tosca.py b/lib/xos-genx/xosgenx/jinja2_extensions/tosca.py
index 04ac3ff..a46770d 100644
--- a/lib/xos-genx/xosgenx/jinja2_extensions/tosca.py
+++ b/lib/xos-genx/xosgenx/jinja2_extensions/tosca.py
@@ -12,6 +12,25 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+def xproto_tosca_required(null, blank, default=None):
+
+    if null == 'True' or blank == 'True' or default != 'False':
+        return "false"
+    return "true"
+
+def xproto_tosca_field_type(type):
+    """
+    TOSCA requires fields of type 'bool' to be 'boolean'
+    TOSCA requires fields of type 'int32' to be 'integer'
+    """
+
+    if type == "bool":
+        return "boolean"
+    elif type == "int32":
+        return "integer"
+    else:
+        return type
+
 def xproto_fields_to_tosca_keys(fields):
 	keys = []
 	# look for explicit keys