1 /* Copyright 2016 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 package org.tensorflow; 17 18 import static org.junit.Assert.assertNotNull; 19 import static org.junit.Assert.assertTrue; 20 import static org.junit.Assert.fail; 21 22 import org.junit.Test; 23 import org.junit.runner.RunWith; 24 import org.junit.runners.JUnit4; 25 26 /** Unit tests for {@link org.tensorflow.SavedModelBundle}. */ 27 @RunWith(JUnit4.class) 28 public class SavedModelBundleTest { 29 30 private static final String SAVED_MODEL_PATH = 31 "tensorflow/cc/saved_model/testdata/half_plus_two/00000123"; 32 33 @Test 34 public void load() { 35 try (SavedModelBundle bundle = SavedModelBundle.load(SAVED_MODEL_PATH, "serve")) { 36 assertNotNull(bundle.session()); 37 assertNotNull(bundle.graph()); 38 assertNotNull(bundle.metaGraphDef()); 39 } 40 } 41 42 @Test 43 public void loadNonExistentBundle() { 44 try { 45 SavedModelBundle bundle = SavedModelBundle.load("__BAD__", "serve"); 46 bundle.close(); 47 fail("not expected"); 48 } catch (org.tensorflow.TensorFlowException e) { 49 // expected exception 50 assertTrue(e.getMessage().contains("SavedModel not found")); 51 } 52 } 53 } 54